[clean-list] FunctionType question

Jigang Sun Jigang.Sun at student.paisley.ac.uk
Thu Jan 25 23:30:53 MET 2007


I am still confused about Type definition. Sometimes it means a list of Type Expression, sometimes it is Type Expression in Clean Documentation.

For example, on page 115 of the Clean Language Report version 2.1, Nov 2002, 

Type Expression = TypeVariable // see A.7
| TypeCnstructorName
| (Type)
| PredefinedType
| PredefinedTypeConstructor

I think "(Type)" means "(Type Expression)". 

on the same page, section A.5, Type is defined as only a list of Type Expresstion with attributes,

Type = {BrackType}+, 
BrackType = [UniversalQuantVariables] [Strict] [UnqTypeAttrib] TypeExpression

which is applied to A.3.1 on page 112

FunctionType = [Type -> ] Type_Expression [ClassContext] [UnqTypeUnEqualities]


on page 43, section 4.6, ArrowType has syntax

ArrowType = (Type -> Type)
Example of an arrow type.
((a b -> c) [a] [b] -> [c])
being equivalent with:
((a -> b -> c) -> [a] -> [b] -> [c])

>From the example given above ((a b -> c) [a] [b] -> [c]) being equivalent with ((a -> b -> c) -> [a] -> [b] -> [c]), there is a similarity/connection between FunctionType and ArrowType, can FunctionType be represented as ArrowType? 

here ArrowType must begin with "(" and ended with ")". 

In A.5.1 ArrowType is of PredefinedType, but its definition is not listed there.

I also think the second Type is different from the first one in "ArrowType = (Type -> Type)", I think ((a b -> c) [a] [b] -> [c] [a]) will be rejected by Clean compiler.

It is well known a function is a value, and has a type, it can be passed as a parameter, but its type FunctionType is not defined as a Type Expression.

on page 26, 
FunctionType = Type -> Type [ClassContext] [UnqTypeUnEqualities]
Type = {BrackType}+

so left side and right side of arrow could be same, but" myFunc :: Int Int -> Int Int " is rejected by compiler, so FunctionType = Type -> Type Expression maybe correct.

"Type" appears many times in Clean grammar, so I need to make it clear.

I wish the documentation could be updated to reflect changes in new released version, and terminology is consistently used.

Thanks.

Jigang



-----Original Message-----
From: Edsko de Vries <devriese at cs.tcd.ie>
To: Jigang Sun <Jigang.Sun at student.paisley.ac.uk>
Date: Thu, 18 Jan 2007 13:19:51 +0000
Subject: Re: [clean-list] FunctionType question

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

---original message:---

I have a simple Start module

module try 
sub :: Int Int -> Int Int 
sub x y = x 3

Start = (sub) 12 23

When I try to run it--
Parse error [try.icl,2;23,Type]: ordinary type variable expected

If I change it to--
module try
sub :: Int Int ->(Int Int) 
sub x y =( x 3 )

Start = (sub) 12 23

When I tried to run it, 
Parse error [try.icl,2;23,Type]: ordinary type variable expected

According to the following grammar, "Int Int" is correct Type syntax, "(Int Int)" is Type Expression syntax, hence a Type.

FunctionType = [Type -> ] Type [ClassContext] [UnqTypeUnEqualities]

Type = {BrackType}+
BrackType = [UniversalQuantVariables] [Strict] [UnqTypeAttrib] TypeExpression

Type Expression = TypeVariable // see A.7
| (Type)
| PredefinedType
...

PredefinedType = BasicType
| ListType
...

BasicType = Int
| Real
| Char

Many thanks.
Jigang






Legal disclaimer
--------------------------

The information transmitted is the property of the University of Paisley and is intended only for the person or entity 
to which it is addressed and may contain confidential and/or privileged material.  Statements and opinions expressed in this e-mail may not represent those of the company.  Any review, retransmission, dissemination and other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited.
If you received this in error, please contact the sender immediately and delete the material from any computer. 

--------------------------




More information about the clean-list mailing list