Skip to content

Instantly share code, notes, and snippets.

@egisatoshi
Created July 17, 2012 14:09
Show Gist options
  • Save egisatoshi/3129576 to your computer and use it in GitHub Desktop.
Save egisatoshi/3129576 to your computer and use it in GitHub Desktop.
Multiset Definition in Egison 2.3
(define $Multiset
(lambda [$a]
(type
{[,$val []
{[$tgt (match [val tgt] [(Multiset a) (Multiset a)]
{[[<nil> <nil>] {[]}]
[[<cons $x $xs> <cons ,x ,xs>] {[]}]
[[_ _] {}]})]}]
[<nil> []
{[{} {[]}]
[_ {}]}]
[<cons ,$px _> [(Multiset a)]
{[$tgt {((remove a) tgt px)}]}]
[<cons _ _> [a (Multiset a)]
{[$tgt (map (lambda [$t] [t ((remove a) tgt t)])
((unique a) tgt))]}]
[<join ,$pxs _> [(Multiset a)]
{[$tgt {((remove-collection a) tgt pxs)}]}]
[<join _ _> [(Multiset a) (Multiset a)]
{[$tgt (map (lambda [$ts] [ts ((remove-collection a) tgt ts)])
(subcollections tgt))]}]
[_ [Something]
{[$tgt {tgt}]}]
})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment