[Haskell-cafe] Re: Strong duck typing / structural subtyping /
type class aliases / ??? in Haskell
Peter Verswyvelen
bugfact at gmail.com
Tue Sep 29 16:58:31 EDT 2009
Yes, the OOHaskell paper blew my mind too, but I still only understood half
of it when reading it for the second time (especially the mfix thing was
scary :-) Not giving up though ;-)
But I wander if the error messages you would get from GHC make it easy to
see what is going wrong. It would be great if a library author could somehow
customize error reporting too, although I have no idea if that is possible.
On Tue, Sep 29, 2009 at 10:03 AM, Alp Mestan <alp at mestan.fr> wrote:
> 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/
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090929/7ac4bf0c/attachment.html
More information about the Haskell-Cafe
mailing list