Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: convincing management to switch to Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Prevost <prevost@m...>
Subject: Re: convincing management to switch to Ocaml
John Skaller <skaller@maxtal.com.au> writes:

> but the latter doesn't work right if I need the parameters
> to have names.  I tried:
> 
> 	let (f: t2 -> t2 -> t3) x y  = something;;
> 
> and that doesn't seem to work? This shape is important,
> where I have a set of functions of the same type,
> with an abbreviation. There seems to be a problem,
> that the operator -> is overloaded in meaning:
> it means 'returns the type' and also 'has the value'.

Hmm.  I guess this is sort of a bit odd--it would make sense for the
above to work, in terms of how type constraints usually work.  (Maybe
this ought to be changed to be more consistent.)

If you need a workaround, however, the following *will* work:

let (f : t2 -> t2 -> t3) = fun x y -> something

likewise, the following (which doesn't put the types up front) will work:

let f = (fun x y -> something : t2 -> t2 -> t3)

Basically, the "reduced form" of let for functions, namely "let f x y
= var" won't allow you to specify the type of the function as a whole,
only the types of the arguments and the type of the result:

let f (x : t2) (y : t2) = (something : t3)

In some ways, this isn't really a problem--one of the big pieces of
utility in the ML family of languages is that type inference allows
you to leave out such type signatures.  And explicit signatures for
modules takes care of the general case.

So, it's sort of an obscure problem.

John.