[Haskell-beginners] curry in a hurry

Brandon S Allbery KF8NH allbery at ece.cmu.edu
Sat Jul 3 19:37:48 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

El sáb, 03-07-2010 a las 15:19 -0700, prad escribió:
>> :t uncurry u
>> uncurry u :: (Num (b -> c)) => ((b -> c, b -> c), b) -> c
>> we're trying to uncurry something that is already uncurried
>>
>> and
>>
>> :t curry c
>> curry c :: (Num (a, b)) => a -> b -> (a, b) -> (a, b)
>> we're trying to curry something that is already curried
>>
>> 3.1 just what are these strange looking things and how should their
>> types be interpreted?

(uncurry u):  "given a function from b to c which is an instance of Num,
transform the pair of pairs ( (b -> c) , (b -> c) , b) to c.  This is easier
to see if you replace (b -> c) with a temporary name `f':  ((f, f), b) -> c.
 Remember that GHC doesn't know what "Num" means, so it is free to invent
apparently nonsensical typeclass members.  (That said, they might actually
be meaningful in some contexts; look up Church numerals.)

(curry c):  you can see this one by re-parenthesizing.  (a -> b) -> ((a,b)
- -> (a,b)), given that (a,b) is an instance of Num.  (Raise a function from a
to b, to a function from a pair (a,b) to another pair (a,b).)  This too
looks odd; but consider Gaussian integers, which are slightly less general,
being ((Num a) => (a,a)).  You could also think of it as a Num with a "tag"
of arbitrary type, ((Num a) => (a,b)).

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwvycwACgkQIn7hlCsL25W7jgCeLdu+iCANQneCHAmGOk4+7QHN
2UAAoJXHCBWP4WaAj9K3Io+pv0h8L1GR
=ti56
-----END PGP SIGNATURE-----


More information about the Beginners mailing list