[mercury-users] Maths and contexts.
Paul Bone
pbone at csse.unimelb.edu.au
Sat Apr 21 09:19:38 AEST 2012
On Sat, Apr 21, 2012 at 01:33:28AM +1000, Julien Fischer wrote:
>
> On Sat, 21 Apr 2012, Julien Fischer wrote:
>
> >The other limitation of this approach is that you are limited to the
> >set of context types that are defined in your program. You cannot
> >construct new contexts at runtime.
>
> You can support construction of contexts at runtime and get compile-time
> checking of contexts mismatches (at the cost of adding an extra word to
> the representation of a number) using existential types. The modified
> decimal module below demonstrates this -- I left most of the fields out
> of the context to save space. The following test program attempts
> to add two decimals that have different contexts associated with them:
Now that there is a value of C in decimal(C), the typeclass can be defined in
terms of C rather than decimal(C).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/users/attachments/20120421/6aa012d3/attachment.sig>
More information about the users
mailing list