[Haskell-cafe] Strong duck typing / structural subtyping / type
class aliases / ??? in Haskell
sebastian.sylvan at gmail.com
Sat Sep 26 00:30:10 EDT 2009
On Fri, Sep 25, 2009 at 10:55 PM, Casey Hawthorne <caseyh at istar.ca> wrote:
> On Fri, 25 Sep 2009 23:25:21 +0200, you wrote:
> >On Fri, Sep 25, 2009 at 8:14 PM, Job Vranish <jvranish at gmail.com> wrote:
> >> Supposedly OCaml has an OO feature that does this but I haven't tried it
> >> out.
> >Indeed, OCaml has stuctural polymorphism, it's a wonderful feature.
> >*# let f myobj = myobj#foo "Hi !";;
> >val f : < foo : string -> 'a; .. > -> 'a = <fun>*
> >IIRC, there has been work on Template Haskell for structural polymorphism.
> Structural subtyping/polymorphism:
> - an object can be coerced to any compatible type, the types do not
> have to be specified ahead of time, that is at compile time.
> - may be overly permissive; some coercions might not make sense
> I wonder how Haskell will minimize the cons, since it is strongly
I kind of think there's no real problem here. If you say that you can accept
any record with a given set of fields, then you have to make sure you make
no other assumptions. This is, in principle, no different from passing a
speed Double to a function that expects a mass Double (e.g. it may produce
garbage for negative values). In both cases a function that requires extra
invariants can enforce it by using a newtype that's constructed and
manipulated in a way which preserves the extra semantic rules.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe