[clean-list] FunctionType question

Edsko de Vries devriese at cs.tcd.ie
Thu Jan 18 14:19:51 MET 2007


On Thu, Jan 18, 2007 at 12:44:37PM +0000, Jigang Sun wrote:
> I have a simple Start module
> 
> module try		
> sub :: Int Int -> Int Int 
> sub x y = x 3
>
> Start =  (sub)  12 23

The type you've given for sub means: I want two integers, and I'm going
to give you back an "Int Int". First of all, an "Int Int" isn't a type;
Int has kind "*", so "Int Int" isn't a well-formed type. "Type Type" is
a valid type expression only if the first type has kind "* -> *", for
example "List Int". That property of the language is however not context
free and can therefore not be enforced by the language grammar. 

Secondly, in the definition of sub, you're applying "x" to "3", so that
would imply that "x" must be a function; so, a suitable type for sub might be

sub :: (Int -> Int) Int -> Int

That however does not match with your use of sub in the expression for
Start, where you are passing in two integers. I can only guess at your
intensions here, but perhaps you meant to return a tuple?

sub :: Int Int -> (Int, Int)
sub x y = (x, y)

Just to emphasize, many properties of the Clean language cannot be
enforced in the grammar, most notable type (and kind) safety. These
properties are checked _after_ the file has been parsed and been
accepted as conform the language grammar. 

Edsko


More information about the clean-list mailing list