[Haskell-cafe] Problem with types

Anupam Jain ajnsit at gmail.com
Fri Aug 19 14:06:21 CEST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110819/866e6e2f/attachment.htm>


More information about the Haskell-Cafe mailing list