Type equivalency 2

Cagdas Ozgenc co19@cornell.edu
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

and

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?

Thanks

----- Original Message -----
From: "Jon Fairbairn" <Jon.Fairbairn@cl.cam.ac.uk>
To: "Cagdas Ozgenc" <co19@cornell.edu>
Cc: "Haskell Cafe List" <haskell-cafe@haskell.org>
Sent: Thursday, June 06, 2002 12:39 AM
Subject: Re: type equivalency


> For example all functions with Int -> Int are type equivalent
> However,
>
> 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
required:

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