[Haskell-cafe] Re: Strong duck typing / structural subtyping / type class aliases / ??? in Haskell

Alp Mestan alp at mestan.fr
Tue Sep 29 04:03:23 EDT 2009


I had never seen this work, it's just awesome !
And it only needs few Haskell extensions.

Is this work deeply documented somewhere except in research papers ? If not,
it could be worth doing, IMO.

On Tue, Sep 29, 2009 at 9:37 AM, <oleg at okmij.org> wrote:

>
> Alp Mestan wrote:
> > Indeed, OCaml has stuctural polymorphism, it's a wonderful feature.
> >
> > *# let f myobj = myobj#foo "Hi !";;
> > val f : < foo : string -> 'a; .. > -> 'a = <fun>*
>
> And Haskell has that too:
>
> > -- This is how we define labels.
> > data Field1 deriving Typeable; field1 = proxy::Proxy Field1
> >
> > -- This is how record selection looks like.
> > foo f = f # field1
>
> The inferred type of  foo is
>
>        *OCamlTutorial> :t foo
>        foo :: (HasField (Proxy Field1) r v) => r -> v
>
> It doesn't seem too different from the OCaml's type; the type variable
> r acts as a row type.
>
> The quoted example is the first from many others described in
>        http://darcs.haskell.org/OOHaskell/OCamlTutorial.hs
>
> The file quotes at length OCaml's Object tutorial and then
> demonstrates how the OCaml code can be written in Haskell.  When it
> comes to objects, structural subtyping, width and depth subtyping,
> etc., Haskell does not seem to miss match compared to OCaml. In
> contrast, Haskell has a few advantages when it comes to coercions
> (one does not have to specify the type to coerce to, as Haskell can
> figure that out). The other files in that directory give many more
> example of encoding C++, Eiffel, OCaml patterns.
>
>


-- 
Alp Mestan
http://blog.mestan.fr/
http://alp.developpez.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090929/f7652ff9/attachment.html


More information about the Haskell-Cafe mailing list