[mercury-users] constructor class syntax

Michael Day mikeday at corplink.com.au
Tue Nov 2 23:05:04 AEDT 1999


> :- func compose(func(T2) = T3, func(T1) = T2) = (func(T1) = T3).
> :- mode compose(func(in) = out is det, func(in) = out is det) =
> 		out(func(in) = out is det) is det.

<snip>

> :- inst fn1 = (func(in) = out is det).
> :- mode fn1_in :: in(fn1).
> :- mode fn1_out :: out(fn1).

Ah I see, thank you. I hadn't yet encountered the Unbounded Joy(tm) of
creating new insts and modes.

> Hasn't Mercury got a lot of equivalence operators (=, ==, ::)?  Is there
> any need for so many?

It seems that type equivalence could be expressed using =, with ample
justification:

 - not using == will confuse Miranda/Haskell programmers
 - using == will confuse C programmers, thinking it is a question

either the two confusions cancel each other out, or it becomes a matter of
who you'd rather confuse. I rather like the fact that in logic
and functional languages there is only one way to state equivalence, no
need to remember assignment and comparison. (Um, ignoring Prolog's bizarre
reliance on =, ==, is, =:=, =@=, and any other things it feels to be
necessary).

Is the use of :: in mode definitions vaguely isomorphic to its (future)
use in denoting field names in structures? Could = be used in one of those
cases, or in both?

:- mode out = free -> ground.

or

:- type triple(T) ---> triple(first = T, second = T, third = T).

both of those look perfectly readable to me, though I say that in total
naivety of what implications it has on the compiler. Has any research been
done on whether token-rich or token-sparse languages are easy for a
*human* to write, and subsequently parse? :)

Michael

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list