Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# Language FunctionalDependencies #-}
- {-# Language UndecidableInstances #-}
- module Prova where
- -- This is taken from the GHC manual on UndecidableInstances,
- -- (“Coverage condition”) on the risks of turning UndecidableInstances
- -- on.
- class Mul a b c | a b -> c where
- (.*.) :: a -> b -> c
- instance Mul Int Int Int where (.*.) = undefined
- instance Mul Int Float Float where (.*.) = undefined
- instance Mul a b c => Mul a [b] [c] where (.*.) = undefined
- f b x y = if b then x .*. [y] else y
- {-
- prova.hs:17:23-25: error:
- • Reduction stack overflow; size = 201
- When simplifying the following type: Mul a0 [[c]] [c]
- Use -freduction-depth=0 to disable this check
- (any upper bound you could choose might fail unpredictably with
- minor updates to GHC, so disabling the check is recommended if
- you're sure that type checking should terminate)
- • In the expression: x .*. [y]
- In the expression: if b then x .*. [y] else y
- In an equation for ‘f’: f b x y = if b then x .*. [y] else y
- -}
- -- If I uncomment the next line, the example works.
- -- f :: Mul a [b] b => Bool -> a -> b -> b
- -- How is is that GHC is not able to infer the required `Mul a [b] b`
- -- constraint?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement