Skip to content

Instantly share code, notes, and snippets.

@ti1024
Created September 3, 2012 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ti1024/3606856 to your computer and use it in GitHub Desktop.
Save ti1024/3606856 to your computer and use it in GitHub Desktop.
Type family and higher-rank type with explicit type signature
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Test2 where
class C a b | b -> a
data A = A
data X = X
data Y = Y
type family TF b
f :: (forall b. (C a b, TF b ~ Y) => b) -> X
f _ = undefined
u :: (C A b, TF b ~ Y) => b
u = undefined
v :: X
v = (f :: (forall b. (C A b, TF b ~ Y) => b) -> X) u -- This line causes an error (see below)
{-
GHC 7.6.1-rc1 (7.6.0.20120810) rejects this code with the following error message.
Test2.hs:24:52:
Couldn't match expected type `Y'
with actual type `TF (forall b. (C A b, TF b ~ Y) => b)'
In the first argument of `f ::
(forall b. (C A b, TF b ~ Y) => b) -> X', namely
`u'
In the expression: (f :: (forall b. (C A b, TF b ~ Y) => b) -> X) u
In an equation for `v':
v = (f :: (forall b. (C A b, TF b ~ Y) => b) -> X) u
GHC 7.4.1 rejected this code with a different error message:
Test2.hs:24:6:
Cannot deal with a type function under a forall type:
forall b. (C A b, TF b ~ Y) => b
In the expression: f :: (forall b. (C A b, TF b ~ Y) => b) -> X
In the expression: (f :: (forall b. (C A b, TF b ~ Y) => b) -> X) u
In an equation for `v':
v = (f :: (forall b. (C A b, TF b ~ Y) => b) -> X) u
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment