[Haskell-cafe] Cannot update a field in a record with a polymorphic type.
Ignat Insarov
kindaro at gmail.com
Sun Sep 6 09:47:58 UTC 2020
Hello.
I have a problem trying to do something very simple.
Consider this conversation with GHC:
λ data Y α = Y {y ∷ α}
λ defaultY = Y {y = mempty}
λ :type defaultY
defaultY :: Monoid α => Y α
λ :type defaultY {y = "c"} ∷ Y String
<interactive>:1:1: error:
• Ambiguous type variable ‘α0’ arising from a use of ‘defaultY’
prevents the constraint ‘(Monoid α0)’ from being solved.
Probable fix: use a type annotation to specify what ‘α0’ should be.
These potential instances exist:
instance Monoid a => Monoid (IO a) -- Defined in ‘GHC.Base’
instance Monoid Ordering -- Defined in ‘GHC.Base’
instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
...plus 7 others
(use -fprint-potential-instances to see them all)
• In the expression: defaultY
In the expression: defaultY {y = "c"} :: Y String
Why does this not work?
More information about the Haskell-Cafe
mailing list