[Haskell-beginners] Re: proper way to read fold types
Brandon S Allbery KF8NH
allbery at ece.cmu.edu
Mon Jul 26 11:16:37 EDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 7/26/10 07:30 , dan portin wrote:
> I'm still a Haskell newbie, so take this with a grain of salt: the type
> signature of /foldr/ and /foldr1/ confuses me also. While I understand how
> each operates, I've never found a description of the type signatures of
> either functions which explains why the function argument of /foldr1/ is of
> type (a -> a -> a) instead of (a -> b -> b). This is the conclusion I came
foldr1 is just foldr where "z" is taken off the end of the list. Therefore,
given [a] as the list type, b (the type of z) unifies with a; and since the
folding function is initially called with z along with the first element of
the list, (a -> b -> b), in the case of foldr1 it is forced to (a -> a -> a).
- --
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/
iEYEARECAAYFAkxNptUACgkQIn7hlCsL25VwrACgkTamfkChSLoWYJUuqXL3vYEs
OMoAoMsJwZHf1of5uBQB7/iUSYjZuyC3
=DF5B
-----END PGP SIGNATURE-----
More information about the Beginners
mailing list