I'm now trying out a piece of code from:
https://mpickering.github.io/posts/2015-12-12-pattern-synonyms-8.html
{-# LANGUAGE PatternSynonyms #-}
pattern MyPoint :: Int -> Int -> (Int, Int)
pattern MyPoint{m, n} = (m,n)
m :: (Int, Int) -> Int
n :: (Int, Int) -> Int
test9 = (0,0) { m = 5 }
But test9
throws an error:
• ‘m’ is not a record selector
• In the expression: (0, 0) {m = 5}
How do I get test9
to work?
When you write:
m :: (Int, Int) -> Int
n :: (Int, Int) -> Int
You're declaring m
and n
as functions and they lose their special place as a record selector. Just drop those lines entirely:
{-# LANGUAGE PatternSynonyms #-}
pattern MyPoint :: Int -> Int -> (Int, Int)
pattern MyPoint{m, n} = (m,n)
test9 = (0,0) { m = 5 } -- (5, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With