Browse thread
Re: [Caml-list] Improving OCaml's choice of type to display
-
Damien Guichard
-
Gilles Pirio
- Lukasz Stafiniak
-
Gilles Pirio
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Lukasz Stafiniak <lukstafi@g...> |
| Subject: | Re: [Caml-list] Improving OCaml's choice of type to display |
You need to use a type alias:
# type ('a, 'b) func = 'a -> 'b;;
type ('a, 'b) func = 'a -> 'b
# let castro a = (fun _ -> a : ('a,'b) func);;
val castro : 'a -> ('b, 'a) func = <fun>
This is also how the compiler decides the arity of C functions from
"external" declarations, that is, it "counts the arrows" without
unfolding type aliases.
On Sun, Oct 11, 2009 at 11:46 PM, Gilles Pirio
<gilles.ocaml@googlemail.com> wrote:
> Hey Damien
>
> Sure, I fully understand that both types are equivalent given the rules
> governing the application operator. My point was more on the usability side,
> as the type display is primarily intended at helping the programmer to
> quickly figure out type mismatch. So I'd think having a display allowing to
> quickly distinguish between the noe and castro functions below would be a
> good thing, especially for beginners. I've been using ocaml for a few years
> now, and I have to say that it's not a major issue any more - just wanted to
> give some feedback about this.
>
> Thanks
> Gilles
>
>
> # let noe a b = a;;
> val noe : 'a -> 'b -> 'a = <fun>
> # let castro a = fun _ -> a;;
> val castro : 'a -> 'b -> 'a = <fun>
>