From: Jonas Jensen <jj@issuu.com>
To: Runhang Li <runhang@posteo.net>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] GADT and weak polymorphism
Date: Sat, 21 Nov 2015 21:37:43 +0100 [thread overview]
Message-ID: <CAExvvWwBCvaDUmC=XzD+ZO5wsOKdBtt=vU2r1L+rwWvNR0L3qA@mail.gmail.com> (raw)
In-Reply-To: <B8C45D30-5709-4A8D-A21C-76197DE32389@posteo.net>
I was asked the same question and found the following stackoverflow
discussion in which two possible remedies are suggested:
http://stackoverflow.com/questions/25025091/ocaml-formatters-and-value-restriction.
Jeffrey Scofield suggests changing your ``l`` to
let l () = '2' **> "str" **> empty
Leo White suggests writing ``l`` so that it's a value rather than an
expression. In your case, you'd write:
module HList = struct
type (_, _) hlist =
| Empty : ('a, 'a) hlist
| :: : 'c * ('a, 'b) hlist -> ('c -> 'a, 'b) hlist
let empty = Empty
let l = '2' :: "str" :: empty
end
I believe that ``::`` is the only infix constructor name in OCaml, so
you have to shadow standard list cons in the module of hlist to make
this work.
In the new ocaml-amqp library, we chose the latter remedy. See the
full result here:
https://github.com/andersfugmann/ocaml-amqp/blob/790486dad/src/amqp_protocol.ml#L197
Cheers,
Jonas
On 17 November 2015 at 19:14, Runhang Li <runhang@posteo.net> wrote:
> Hi, camels
>
> Consider the following module:
>
> module HList = struct
>
> type (_, _) hlist =
> | Empty : ('a, 'a) hlist
> | Cons : 'c * ('a, 'b) hlist -> ('c -> 'a, 'b) hlist
>
> let cons : type a b c. c -> (a, b) hlist -> (c -> a, b) hlist =
> fun h tl -> Cons (h, tl)
>
> let empty = Empty
>
> let ( **> ) = cons
>
> let l = '2' **> "str" **> empty
>
> end
>
> The type of ``l`` is ``(char -> string -> ‘_a, ‘_a) hlist``. I would like to know the reason that weak polymorphism shows up here.
>
> Thank you
>
>
> Kindly,
>
> Runhang
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
prev parent reply other threads:[~2015-11-21 20:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 18:14 Runhang Li
2015-11-19 9:09 ` Gabriel Scherer
2015-11-21 20:37 ` Jonas Jensen [this message]
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='CAExvvWwBCvaDUmC=XzD+ZO5wsOKdBtt=vU2r1L+rwWvNR0L3qA@mail.gmail.com' \
--to=jj@issuu.com \
--cc=caml-list@inria.fr \
--cc=runhang@posteo.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