[Haskell] Type Lambdas in Gofer

Stefan O'Rear stefanor at cox.net
Wed Aug 1 02:15:20 EDT 2007


On Wed, Aug 01, 2007 at 07:57:48AM +0200, Wolfgang Lux wrote:
> Jim Apple wrote:
>
>> data Rec f = In (f (Rec f))
>> type P f a = f (Rec f, a)
>>
>> mapP :: Functor f => (a -> b) -> P f a -> P f b
>> mapP g = fmap (\(x,a) -> (x, g a))
>>
>> instance Functor f => Functor (P f) where
>>     fmap = mapP
>>
>> Why did Gofer have this power while Haskell does not?
>
> Haskell does have the same power as Gofer, it simply does
> not allow you to define instances for type synonyms (just
> in order to prevent overlapping instances, I guess). If
> you use a newtype instead of a type synonym everything
> works fine:

Quite probably they never bothered to test it.

stefan at stefans:/usr/local/src/gofer$ tail -15 standard.prelude 
openfile f       = primFopen f (error ("can't open file "++f)) id

-- End of Gofer standard prelude: --------------------------------------------

class Functor f where
  fmap :: (a -> b) -> f a -> f b

data Rec f = In (f (Rec f))
type P f a = f (Rec f, a)

mapP :: Functor f => (a -> b) -> P f a -> P f b
mapP g = fmap (\(x,a) -> (x, g a))

instance Functor f => Functor (P f) where
    fmap = mapP
stefan at stefans:/usr/local/src/gofer$ src/gofer 
Gofer Version 2.30b  Copyright (c) Mark P Jones 1991-1995

Reading script file "standard.prelude":
       
ERROR "standard.prelude" (line 874): Not enough arguments for type synonym "P"

FATAL ERROR: Unable to load prelude
stefan at stefans:/usr/local/src/gofer$ 

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell/attachments/20070731/d83bd2c7/attachment.bin


More information about the Haskell mailing list