caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: "ocaml_beginners"::[] Syntax for polymorphic methods
       [not found]   ` <301730110702260959i561902dar1a26dceb5a11fd2c@mail.gmail.com>
@ 2007-02-26 19:02     ` Lukasz Stafiniak
  2007-02-27  4:37       ` [Caml-list] " Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Lukasz Stafiniak @ 2007-02-26 19:02 UTC (permalink / raw)
  To: ocaml_beginners, caml users

On 2/26/07, Geoffrey Romer <geoff.romer@gmail.com> wrote:
>
> So what's the difference between 'a. <stuff> and just plain <stuff>? Aren't
>  type variables implicitly universally quantified (i.e. isn't the whole point
>  of a polymorphic type that it applies for any possible 'a)?
>
You've got me here...

        Objective Caml version 3.09.3

# type pty = {pv : 'a . 'a list};;
type pty = { pv : 'a. 'a list; }
# let px = {pv = []};;
val px : pty = {pv = []}
# match px with
    {pv=[]} -> "OK"
  | {pv=5::_} -> "int"
  | {pv=true::_} -> "bool";;
      Fatal error: exception Assert_failure("typing/parmatch.ml", 784, 55)

Process caml-toplevel exited abnormally with code 2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Re: "ocaml_beginners"::[] Syntax for polymorphic methods
  2007-02-26 19:02     ` "ocaml_beginners"::[] Syntax for polymorphic methods Lukasz Stafiniak
@ 2007-02-27  4:37       ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2007-02-27  4:37 UTC (permalink / raw)
  To: lukstafi; +Cc: ocaml_beginners, caml-list

From: "Lukasz Stafiniak" <lukstafi@gmail.com>
>         Objective Caml version 3.09.3
> 
> # type pty = {pv : 'a . 'a list};;
> type pty = { pv : 'a. 'a list; }
> # let px = {pv = []};;
> val px : pty = {pv = []}
> # match px with
>     {pv=[]} -> "OK"
>   | {pv=5::_} -> "int"
>   | {pv=true::_} -> "bool";;
> Fatal error: exception Assert_failure("typing/parmatch.ml", 784, 55)

Thanks for finding a small bug.
The code above is meaningless: only the empty list has type
  forall 'a. 'a list.
Yet one could write it, and invalidate some internal invariant of the
compiler.
Now (for 3.10) this triggers an error message:

  The record field label pv is polymorphic.
  You cannot instantiate it in a matching.

An aside of the fix is that matching a polymorphic field with a
variable now generates a polymorphic binding.

  # fun {pv=v} -> true::v, 1::v;;
  - : pty -> bool list * int list = <fun>

Jacques Garrigue


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-27  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <301730110702251711h258dd326nb8a38f6751c4c8ea@mail.gmail.com>
     [not found] ` <4a708d20702260334i47bbde3fgcdf2ca2c296338c8@mail.gmail.com>
     [not found]   ` <301730110702260959i561902dar1a26dceb5a11fd2c@mail.gmail.com>
2007-02-26 19:02     ` "ocaml_beginners"::[] Syntax for polymorphic methods Lukasz Stafiniak
2007-02-27  4:37       ` [Caml-list] " Jacques Garrigue

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).