caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andreas Rossberg <rossberg@mpi-sws.org>
To: Brigitte Pientka <bpientka@cs.mcgill.ca>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] recursive records
Date: Fri, 8 Nov 2013 21:17:15 +0100	[thread overview]
Message-ID: <EF3E99AA-C0A7-41A8-8936-C550F38DC41B@mpi-sws.org> (raw)
In-Reply-To: <527D452E.90701@cs.mcgill.ca>

On Nov 8, 2013, at 21:10 , Brigitte Pientka <bpientka@cs.mcgill.ca> wrote:
> I am playing around with using recursive records to define observations about
> streams simulating essentially the ideas described in "Copatterns:Programming infinite structures by observations" presented at POPL'13.
> 
> type 'a susp = Susp of (unit -> 'a)
> 
> type 'a str = {hd: 'a  ; tl : ('a str) susp}
> 
> let rec ones = {hd = 1 ; tl = Susp (fun () -> ones)}
> 
> This works fine and many examples can be elegantly written this way.  However,
> when I define the stream ones via the function delay, OCaml fails.
> 
> let delay f = Susp f
> 
> let rec ones = {hd = 1 ; tl = delay (fun () -> ones)};;
> Characters 15-53:
>  let rec ones = {hd = 1 ; tl = delay (fun () -> ones)};;
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error: This kind of expression is not allowed as right-hand side of `let rec'
> 
> Could someone explain why this fails?

Roughly speaking, let rec only allows syntactic values as right-hand sides (to ease implementation and to avoid issues with potential observable side effects during tying of the recursive knot). An application like the one of delay is not a value. If you replace it by a direct application of the Susp constructor it should work.

/Andreas


  reply	other threads:[~2013-11-08 20:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 20:10 Brigitte Pientka
2013-11-08 20:17 ` Andreas Rossberg [this message]
2013-11-08 21:56   ` Alain Frisch
2013-11-09  4:02 ` oleg
2013-11-13  8:01   ` Arkady Andrukonis

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=EF3E99AA-C0A7-41A8-8936-C550F38DC41B@mpi-sws.org \
    --to=rossberg@mpi-sws.org \
    --cc=bpientka@cs.mcgill.ca \
    --cc=caml-list@inria.fr \
    /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).