caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "Jim Farrand" <jim@farrand.net>
Cc: "Caml Mailing List" <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Typeclasses in OCaml (Was: Haskell vs OCaml)
Date: Thu, 14 Aug 2008 19:37:06 +0100	[thread overview]
Message-ID: <9d3ec8300808141137i2b5e606fh2f4803843ef13e88@mail.gmail.com> (raw)
In-Reply-To: <e16c7bcd0808140904k6ccdf737vc837751bfb8d98be@mail.gmail.com>

Typw inference in haskell is not decideable (nor is it in ocaml when
using objects) and you have to provide some type information. I would
much rather trade some inference for more power in the type system
(value restriction and lack of higher rank polymorphic really kill
some coding styles....) but thta is a matter of taste. Didier Remy is
working on ML F which should address those.

On top of breaking inference type cleases come at a high run tine
cost. You can regain a lot by doing ad-hoc optimizations but this is
quite far from OCaml's philosophy: the compiler's optimisations (or
lack thereof) are very predictable which is nice once you move out of
toy programs.

Till
On Thu, Aug 14, 2008 at 5:04 PM, Jim Farrand <jim@farrand.net> wrote:
> 2008/8/14 Peng Zang <peng.zang@gmail.com>:
>
>>  (=) : 'a -> 'a -> bool
>>
>> But instead:
>>
>>  (=) : (#equatable as 'a) -> 'a -> bool
>>
>> where
>>
>>  class type equatable = object
>>    method equals : 'self -> bool
>>  end
>>
>>
>> This gives all the advantages of static typing and type inference and prevents
>> stupid errors and it is meaningful for all types that it is implemented for.
>
> This doesn't answer my question at all.  :)
>
>  Is there any theoretical reason they couldn't added?  The kind of
> answer I'm looking for is "There is no theoretical reason why not", or
> "This is impossible as it would cause typing in OCaml to become
> undecidable, due to interactions with other features of the OCaml type
> system which aren't present in Haskell."
>
> Though, to address your solution, I am of course aware of it, but it
> has what seem like big disadvantages:
>
> 1. Every value in OCaml would then have to be an object
> 2. Every comparison now requires a relatively expensive dynamic
> dispatch, when the correct function could be determined at runtime.
> 3. If I add a new operator that wasn't thought of by the language
> implementors, it can't be easily added to primitive values, without
> either subclassing all of them, or changing the definition in the
> standard library to add the new method.
>
> Regards,
> Jim
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  parent reply	other threads:[~2008-08-14 18:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-14 14:46 Jim Farrand
2008-08-14 15:21 ` [Caml-list] " Peng Zang
2008-08-14 15:38   ` Jon Harrop
2008-08-14 16:04   ` Jim Farrand
2008-08-14 17:13     ` Peng Zang
2008-08-14 18:37     ` Till Varoquaux [this message]
2008-08-15 11:03       ` Wolfgang Lux
2008-08-14 20:53 ` Nathaniel Gray
2008-08-14 22:33   ` Erik de Castro Lopo
2008-08-15  0:21 ` Brian Hurt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d3ec8300808141137i2b5e606fh2f4803843ef13e88@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jim@farrand.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).