logo       

Re: higher-order typing errors: msg#00049

lang.haskell.glasgow.bugs

Subject: Re: higher-order typing errors

Hi!

On Thu, Jan 23, 2003 at 10:28:13AM -0000, Simon Peyton-Jones wrote:
>
> To get around it, define your own data type:
>
> data MyPr = MyPr (forall a.a->a) (forall a.a->a)
>
> swap1 :: MyPr -> MyPr

I played a bit with using highed order polymorphism for this problem,
and have encountered compile errors I don't understand.

The first version doesn't compile - the error is:
Type synonym `F3' should have 1 argument, but has been given 0
In the type: Pair F3 F2
While checking the type signature for `p'

{-# OPTIONS -fglasgow-exts #-}

module T where

type F3 a = a -> a -> a
type F2 a = a -> a

data Pair c1 c2 = Pair (forall a. c1 a) (forall b. c2 b)

swap :: Pair c1 c2 -> Pair c2 c1
swap (Pair f g) = Pair g f

f2 :: F2 a
f2 = id

f3 :: F3 a
f3 = const

p :: Pair F3 F2
p = Pair f3 f2

The other version uses newtype instead of type synonyms for F2 and F3.
This one compiles without problems.

{-# OPTIONS -fglasgow-exts #-}

module T2 where

newtype F3 a = F3 (a -> a -> a)
newtype F2 a = F2 (a -> a)

data Pair c1 c2 = Pair (forall a. c1 a) (forall b. c2 b)

swap :: Pair c1 c2 -> Pair c2 c1
swap (Pair f g) = Pair g f

f2 :: F2 a
f2 = F2 id

f3 :: F3 a
f3 = F3 const

p :: Pair F3 F2
p = Pair f3 f2

There is probably some restriction I don't know about or haven't
recognized in this particular case. I hope you will enlighten me.

> Simon

Best regards,
Tom

--
.signature: Too many levels of symbolic links


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise