Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Is arrow programming impossible in ocaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Is arrow programming impossible in ocaml?
From: Oleg Trott <oleg_trott@columbia.edu>
> On Monday 13 October 2003 07:59 pm, Nick Name wrote:
> > Hi all, I am trying to work on a project where I need ocaml efficiency
> > with rank-2 polymorphism, if I got it correctly (I am not an expert in
> > programming language semantics).
> >
> > Basically I am trying to reproduce FRAN-like usage of arows as in
> >
> > http://haskell.cs.yale.edu/yampa/AFPLectureNotes.pdf
> >
> > so I have defined my own arrow module etc, but I faced the rank-1
> > polymorphism restriction of ocaml. I have cut down my example to:

Looking at your example, this doesn't seem to be a problem with rank-2
polymorphism, but just one instance of the value restriction.
(See the FAQ on caml.inria.fr)

> > -
> > type ('a,'b) t = 'a -> 'b
> >
> > let rec arr f = f
> >
> > let a = arr (fun x -> x)
> > -
> >
> > and "a" is typed like '_a -> '_a , where I would like it to be typed 'a
> > -> 'a.
> 
> I think OCaml 3.07 makes this possible

Unfortunately, no. OCaml 3.07 recovers polymorphism only if 'a appears
only in covariant positions, and here it appears in both covariant and
contravariant position.

But as long as you represent arrows by normal functions (as this seems
to be the case in the paper), eta-expanding should solve the problem.

  let a y = arr (fun x -> x) y

Not also that there is no problem if Arr is a constructor:

  type ('a,'b) = Arr of ('a -> 'b)

  let a = Arr (fun x -> x)

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners