[Haskell-cafe] Re: Transparent identity instances

Maciej Piechotka uzytkownik2 at gmail.com
Mon Nov 29 17:30:48 CET 2010


On Sun, 2010-11-28 at 22:59 +0800, Jafet wrote:
> > {-# LANGUAGE TypeSynonymInstances #-}
> > type Identity a = a
> > instance Applicative Identity where
> >   -- something like
> >   pure a = a
> >   f <*> a = f a
> 
> But GHC does not accept type synonym instances unless they are fully
> applied.
> 
> Is it sound for such an instance to exist? If so, how might it be
> defined? 

> data Tag a = Tag
>
> instance Applicative Tag where
>     pure _ = Tag
>     Tag <*> Tag = Tag
>
> cast :: Tag a -> Tag b
> cast Tag = Tag

1. pure id <*> Tag = Tag

2. I'm too lazy to prove it

3. pure f <*> pure x = Tag <*> Tag = Tag = pure (f x)

4. u <*> pure y = u <*> Tag = u = Tag <*> u = pure ($ y) <*> u

> x = pure undefined
> y = x :: Tag ()

Is y defined?

pure!Tag undefined = Tag
pure!Identity undefined = undefined

Regards
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20101129/83df3f07/attachment.bin


More information about the Haskell-Cafe mailing list