Type equivalency 2
Thu, 6 Jun 2002 10:40:36 +0300
>From the previous discussion it has been brought to my attention that there
is no much difference between
a -> b
data F a b = Blank a b -- "-> probably has a blank value constructor"
Therefore it should be trivial to define a label initialized to a function
abstraction without using the -> type constructor. I mean
fun :: F Int Int
fun ? = ?
now what do I write in place of 1st and 2nd question marks? Even if I can do
this, how am I suppose to invoke fun so that it would yield an "Int" not a
"F Int Int"?
Or maybe I should ask the following question: what would the "value
constructor" of -> look like, theoretically?
----- Original Message -----
From: "Jon Fairbairn" <Jon.Fairbairn@cl.cam.ac.uk>
To: "Cagdas Ozgenc" <firstname.lastname@example.org>
Cc: "Haskell Cafe List" <email@example.com>
Sent: Thursday, June 06, 2002 12:39 AM
Subject: Re: type equivalency
> For example all functions with Int -> Int are type equivalent
> data D a b = MkD a b
All objects D Int Int are type equivalent. I'm not sure what
your question means, otherwise.
If you define
data Function a b = F (a -> b)
apply:: Function a b -> a -> b
apply (F f) a = f a
you add an extra level of constructor, but you can still use
anything of type Function Int Int where Function Int Int is
square:: Function Int Int
square = F (\ a -> a*a)
sqare_root:: Function Int Int
square_root = F (\ a -> round (sqrt (fromIntegral a)))
E&OE -- it's about my bedtime