syntax across languages

Jay Cox
Mon, 11 Feb 2002 20:59:07 -0600 (CST)

On 11 Feb 2002, Pixel wrote:

> Jay Cox <> writes:
> > Using
> >
> > data = Foo ...
> > really should be meantioned as a way to construct new types.
> > newtype = Foo ... (new type)
> >
> > type Foo = ...
> > is only a type synonym. heres an example.
> > type String = [Char]
> ok (i won't mention that i always have a hard time dinstiguishing them)

Actually, I guess really should have explained myself a bit further.

data Foo = ... only way to construct new structures (like lists,Trees,
algebraic data types, enums, blah).  Perhaps a (contrived) example for
your syntax could be like a cross between a Tree and the Either type as in

data Foo a b = FooLeft a | FooRight b | Tree (Foo a b) (Foo a b)

So now you can construct values of say Foo Integer String.

(I guess its a cousin to templates in C++)
Or perhaps you need a separate section for syntax
for constructing new datatypes..

data Foo x ... = A | B x ... | C (Foo ...) | ...

the above expresses the fact that
1. Foo can "map" over any type x,y,etc
2. you can have (0 or more) argument constructors
3. datatypes can be recursive.

Now, newtype Foo = ... like "type" but creates a new type as far as the
type checker is concerned.

type String = [Char]
newtype String2 = [Char]

foo:: String <=> foo :: [Char]
but not foo::String2 <=> foo :: [Char]

(Please dont take this as an insult by my re-explaining these things.
I just want to make myself clear.)

> > Under constrol structure, at least give mention to monads!
> > Common examples (ST,IO,List,Maybe) and "do notation"
> >
> > Monads are defined by instanciating them under the Monad type class.
> > (basically giving definitions for the operators >>= (aka 'bind') and >>
> please be more precise, what do i put? in which category?

I guess I suggested control structure because in a way, you can "control
the flow" from a semantic point of view of your program by building /
choosing a specific monad.  For instance, usage of the List monad brings
nondeterminism into the language (although, in reality,
the multiple solutions alluded to by the term are elements of a
deterministically (is that a word?!) produced list)

do  x<-[1,2,3]
    if (y<6) then return (10*x + y)
    else fail ""


aside: this is a rough and perhaps slightly incorrect translation from
[10*x + y | x<-[1,2,3],y<-[4,5,6],y<6]

However, the concept of a monad is language independent.  It's just
that Haskell does so much to accomodate them.

I suppose a sollution to what to do with do-notation is to put something

do stmnt
   var <-stmtn

or do {stmnt; var <-stmtn; etc}

under your section named "Various Operators" with description
"do statments under monad"

> is this a good approximate syntax?
> [ f x0 x1 ... | x0 <- a_list, pred x0, ... ]


> >
> > References arent missing.  They are implemented under both the ST and IO
> > monads.
> what is the syntax?

no syntax, only functions which create/manipulate them (under some monad).

do{ x<-newSTRef exp; y <-readSTRef x; writeSTRef x exp}

for IORefs do s/ST/IO/g to above line.

I suppose that truely this isn't part of the main specs (not in Haskell
Report/Haskell Library Report but implemented in ghc & Hugs iirc and
modules must be imported, etc) so this concept of "Reference" in Haskell
to might too be omitted, unless you want to contrast with SML.

Jay Cox