[m-users.] Existential types example

Volker Wysk post at volker-wysk.de
Sat Oct 1 04:11:42 AEST 2022


P.S.:

> I've tried the following example from the Mercury Language Reference Manual,
> section 11.3 Existentially typed data types:
> 
> 
> :- typeclass showable(T) where [ func show(T) = string ].
> 
> :- type s
>     --->    some [T] (s(T) => showable(T)).
> 
> :- type list_of_showable == list(s).
> 
> :- instance showable(int)    where [ show(I) = string.string(I) ].
> :- instance showable(string) where [ show(S) = S ].

This part:

> :- func hetlist = list_of_showable.
> hetlist = [ s(123), s("bla") ].         % <-- line 63

... is by me. It isn't part of the example above.


Bye
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20220930/d4111e12/attachment.sig>


More information about the users mailing list