Dimensional analysis with fundeps

Ashley Yakeley ashley@semantic.org
Thu, 19 Apr 2001 01:19:09 -0700


--Emailer_-1223877178
Content-Type: text/plain; charset="US-ASCII"

At 2001-04-09 10:29, Dylan Thurston wrote:

>I hadn't thought about doing rational arithmetic with GCDs.  Might be
>nice.

Herewith my attempt. I can't test it though, it runs afoul of one of the 
many bugs in Hugs' type-extension handling, and I haven't been able to 
run GHC on my MacOS X box.

-- 
Ashley Yakeley, Seattle WA

--Emailer_-1223877178
Content-Type: application/octet-stream; name="MarkerType.hs";
 x-mac-type="54455854";
 x-mac-creator="522A6368"
Content-transfer-encoding: base64
Content-Disposition: Attachment; filename="MarkerType.hs"

LS0gVGhpcyBpcyB3cml0dGVuIGluIEhhc2tlbGwuCm1vZHVsZSBNYXJrZXJUeXBlIHdoZXJlCgl7
CglkYXRhIFNpbmdsZXRvbiBhID0gU2luZ2xldG9uOwoKCWluc3RhbmNlIFNob3cgKFNpbmdsZXRv
biBhKSB3aGVyZQoJCXsKCQlzaG93IFNpbmdsZXRvbiA9ICJzaW5nbGV0b24iOwoJCX07CgoJLS0g
Qm9vbGVhbnMgZXhwcmVzc2VkIGFzIEhhc2tlbGwgdHlwZXMuCglkYXRhIFRydWU7CglkYXRhIEZh
bHNlOwoJCgljbGFzcyBCb29sZWFuVHlwZSBhOwoJaW5zdGFuY2UgQm9vbGVhblR5cGUgVHJ1ZTsK
CWluc3RhbmNlIEJvb2xlYW5UeXBlIEZhbHNlOwoKCWNsYXNzIElzIGE7CglpbnN0YW5jZSBJcyBU
cnVlOwoKCWNsYXNzIElzbnQgYTsKCWluc3RhbmNlIElzbnQgRmFsc2U7CgoJY2xhc3MgRWl0aGVy
SXMgYSBiOwoJaW5zdGFuY2UgRWl0aGVySXMgVHJ1ZSBiOwoJaW5zdGFuY2UgRWl0aGVySXMgRmFs
c2UgVHJ1ZTsKCgljbGFzcyBCb3RoQXJlIGEgYjsKCWluc3RhbmNlIEJvdGhBcmUgVHJ1ZSBUcnVl
Ow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