[clean-list] Function Arity

Sean Seefried seefried@itee.uq.edu.au
Thu, 28 Mar 2002 14:34:51 +1000


Dear users of Clean,

I have recently been experimenting with Clean (as you can see from the
number of posts to this group).
Recently I have run across the "function arity" aspect of the Clean typing
system.  This is something which other functional programming languages such
as Haskell do not have.

Consider the following Haskell code which I was porting to Clean.

type Point = (Float, Float)
type Image c = Point -> c
type ImageC  =  Image Colour  -- don't wory about definition of Colour
type Region = Image Bool

regionToImageC :: Region -> ImageC
regionToImageC reg p = if (reg p) then black else white -- black and white
are predefined colours.

--------
Now consider the following (wrong) Clean code.
----
:: Point :== (Int, Int)
:: Image c :== Point -> c
:: ImageC :== Image Colour
:: Region :== Image Bool

regionToImageC :: Region -> ImageC
regionToImageC reg p
      | reg p       = black
      | otherwise = white

-----
This causes a type error in Clean.  Why? Because the arity of regionToImageC
is 1 not 2!
I am forced to rewrite this as

regionToImageC :: Region -> ImageC
regionToImageC reg = im
                                    where im p
                                         | reg p       = black
                                         | otherwise = white


----

The problem is I don't like the second definition as much, mainly because I
like the type synonyms that I've used.  In my opinon, they enhance the
readability of the code.  If function arity is required for efficiency
reasons could someone please let me know why it is not possible to work out
arity information at compile time.  Why does it have to be supplied by the
programmer?

It appears someone else has had the same gripe as me.
I refer you to the site.

http://www.cs.kun.nl/~clean/archives/clean-list/0375.html



Sean Seefried