Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recursive Unions


On Thu, 16 Aug 2018 20:00:56 -0400
Yves Cloutier <yves.cloutier@xxxxxxxxx> wrote:

> Well Ori, that certainly did the job!
> 
> I'm following examples from the book "Programming Language Concepts" by
> Peter Sestoft.
> 
> The book uses F# for the implementation of the examples. I thought I would
> try to follow along using Myrrdin.
> 
> As a followup question, the F# version of Prim is:
> 
> Prim (string, Expression Expression)
> 
> I used byte[:] here after looking at some examples. looking at the string
> package and seeing byte[:] I just assumed is was similar to a C char* or
> char[].
> 
> Is this correct? there is no "string" type?
> 

That's correct, although it isn't a direct equivalent. byte[:] stores
the length of the sequence and checks bounds. The APIs uniformly assume
that the byte[:] is encoded as utf-8.

Also, note that in Myrddin, char is a utf32 code point, and not a byte.
This means you would stream through a string character by character using
something like:

	for c : std.bychar(str)
		frob(c)
	;;

You *can* index strings, although often it's a bad idea -- and comparing
with characters without a cast or decode will give an error:

	if str[0] == ':' // error
	if std.decode(str) == ':' // ok

You can also iterate by graphemes, thanks to npnth, which means that
you get all the combining characters as a unit:

	for g : std.bygrapheme(str)
		frob(g)
	;;

-- 
Ori Bernstein <ori@xxxxxxxxxxxxxx>

References:
Recursive UnionsYves Cloutier <yves.cloutier@xxxxxxxxx>
Re: Recursive UnionsOri Bernstein <ori@xxxxxxxxxxxxxx>
Re: Recursive UnionsYves Cloutier <yves.cloutier@xxxxxxxxx>