[Haskell-cafe] Problem with types

MigMit miguelimo38 at yandex.ru
Fri Aug 19 14:28:16 CEST 2011


p :: (forall o. M o -> M o) -> ...

Отправлено с iPad

19.08.2011, в 16:06, Anupam Jain <ajnsit at gmail.com> написал(а):

> Hi all,
> 
> Suppose I have a compound data type -
> 
> data M o = M (String,o)
> 
> Now, I can define a function that works for ALL M irrespective of o. For example -
> 
> f :: M o -> M o
> f (M (s,o)) = M (s++"!", o)
> 
> I can also use this function in an expression, applying it to different types without problem -
> 
> p = (m1',m2') where
>   m1 = M ("1", ())
>   m2 = M ("2", True)
>   m1' = f m1
>   m2' = f m2
> 
> Main*> p
> (M ("1!",()),M ("2!",True))
> 
> However, if I try to parameterise over the function 'f' it does not work!  -
> 
> p f = (m1',m2') where
>   m1 = M ("1", ())
>   m2 = M ("2", True)
>   m1' = f m1
>   m2' = f m2
> 
> It doesn't even typecheck, producing the error - "Couldn't match expected type 'Bool' with actual type '()'"
> 
> Is there a particular reason for this? How can I define a function like 'p' within Haskell?
> 
> Thanks,
> Anupam Jain
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list