[Haskell-beginners] instances of different kinds
Brandon S Allbery KF8NH
allbery at ece.cmu.edu
Fri Aug 27 23:21:48 EDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 8/27/10 22:58 , Greg wrote:
> I guess the problem I'm having is finding a way to treat parametric and
> non-parametric types interchangeably. The syntax doesn't seem to exist that
> will allow me to say:
>
> div2pi :: (Floating a) => a -> a -- for non parametric types (ie. Float)
> and
> div2pi :: (Floating b) => a b -> b -- for parametric types (ie. Foo Float)
It occurs to me that what you really want *may* be:
> class (Floating a, Floating b) => TwoPi a b | a -> b where
> div2pi :: a -> b
which says that, given a specific type a, the compiler can infer a specific
type b corresponding to it, without specifying what that type is (leaving
the instance declaration to do so).
- --
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/
iEYEARECAAYFAkx4gMwACgkQIn7hlCsL25UaKwCgpe6hlJQ0yCDL2GtbO7EsrePe
Cp4An3mEUz6PH23v9z0SHbmP6ikmm/yL
=YIZH
-----END PGP SIGNATURE-----
More information about the Beginners
mailing list