Advertisement
Guest User

Untitled

a guest
Nov 19th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# Language FunctionalDependencies #-}
  2. {-# Language UndecidableInstances #-}
  3.  
  4. module Prova where
  5.  
  6. -- This is taken from the GHC manual on UndecidableInstances,
  7. -- (“Coverage condition”) on the risks of turning UndecidableInstances
  8. -- on.
  9.  
  10. class Mul a b c | a b -> c where
  11.   (.*.) :: a -> b -> c
  12.  
  13. instance Mul Int Int Int where (.*.) = undefined
  14. instance Mul Int Float Float where (.*.) = undefined
  15. instance Mul a b c => Mul a [b] [c] where (.*.) = undefined
  16.  
  17. f b x y = if b then x .*. [y] else y
  18.  
  19. {-
  20.  
  21. prova.hs:17:23-25: error:
  22.     • Reduction stack overflow; size = 201
  23.       When simplifying the following type: Mul a0 [[c]] [c]
  24.       Use -freduction-depth=0 to disable this check
  25.       (any upper bound you could choose might fail unpredictably with
  26.        minor updates to GHC, so disabling the check is recommended if
  27.        you're sure that type checking should terminate)
  28.     • In the expression: x .*. [y]
  29.       In the expression: if b then x .*. [y] else y
  30.       In an equation for ‘f’: f b x y = if b then x .*. [y] else y
  31. -}
  32.  
  33. -- If I uncomment the next line, the example works.
  34. -- f :: Mul a [b] b => Bool -> a -> b -> b
  35.  
  36. -- How is is that GHC is not able to infer the required `Mul a [b] b`
  37. -- constraint?
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement