Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Created August 26, 2018 23:48
Show Gist options
  • Save pedrofurla/4804c58db32a429078309f5cfee51d43 to your computer and use it in GitHub Desktop.
Save pedrofurla/4804c58db32a429078309f5cfee51d43 to your computer and use it in GitHub Desktop.
Why the declaring types drives GHC crazy?
lift3 ::
Applicative f =>
(a -> b -> c -> d)
-> f a
-> f b
-> f c
-> f d
lift3 f a b c =
{-let -- This produces the error below
g :: f (c -> d)
g = lift2 f a b
in-}
lift2 f a b <*> c
{-
• Couldn't match type ‘c’ with ‘c1’
‘c’ is a rigid type variable bound by
the type signature for:
lift3 :: forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
at src/Course/Applicative.hs:(189,1)-(195,8)
‘c1’ is a rigid type variable bound by
the type signature for:
g :: forall (f1 :: * -> *) c1 d1. f1 (c1 -> d1)
at src/Course/Applicative.hs:199:5-19
Expected type: f1 (c1 -> d1)
Actual type: f (c -> d)
• In the expression: lift2 f a b
In an equation for ‘g’: g = lift2 f a b
In the expression:
let
g :: f (c -> d)
g = lift2 f a b
in g <*> c
• Relevant bindings include
g :: f1 (c1 -> d1) (bound at src/Course/Applicative.hs:200:5)
c :: f c (bound at src/Course/Applicative.hs:197:13)
f :: a -> b -> c -> d (bound at src/Course/Applicative.hs:197:7)
lift3 :: (a -> b -> c -> d) -> f a -> f b -> f c -> f d
(bound at src/Course/Applicative.hs:197:1)
|
200 | g = lift2 f a b
| ^^^^^^^^^^^
Failed, 12 modules loaded.
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment