summaryrefslogtreecommitdiff
path: root/assignment-9/sets.icl
diff options
context:
space:
mode:
Diffstat (limited to 'assignment-9/sets.icl')
-rw-r--r--assignment-9/sets.icl23
1 files changed, 13 insertions, 10 deletions
diff --git a/assignment-9/sets.icl b/assignment-9/sets.icl
index b277ff8..f85ef26 100644
--- a/assignment-9/sets.icl
+++ b/assignment-9/sets.icl
@@ -63,6 +63,9 @@ surround x y p = pr x o p o pr y
parens :: (Print -> Print)
parens = surround "(" ")"
+pBetween :: a Print Print -> Print | toString a
+pBetween g x y = parens (between g x y)
+
// Convenience
INT :: (Element -> Element); INT = id
SET :: (Set -> Set); SET = id
@@ -98,17 +101,17 @@ instance :- Set Element where :- = flip $ flip (-) o fmap pure
instance *: Element Set where *: = liftA2 $ map o (*)
instance integer Print where integer = pr
-instance set Print where set = \xs -> pr "[" o prsperse "," xs o pr "]"
+instance set Print where set = surround "[" "]" o prsperse ","
instance size Print Print where size = surround "size (" ")"
-instance + Print where + a b = parens (between " + " a b)
-instance - Print where - a b = parens (between " - " a b)
-instance * Print where * a b = parens (between " * " a b)
+instance + Print where + a b = pBetween " + " a b
+instance - Print where - a b = pBetween " - " a b
+instance * Print where * a b = pBetween " * " a b
-instance +: Print Print where +: = \a b -> parens (between " +: " a b)
-instance :+ Print Print where :+ = \a b -> parens (between " :+ " a b)
-instance :- Print Print where :- = \a b -> parens (between " :- " a b)
-instance *: Print Print where *: = \a b -> parens (between " *: " a b)
+instance +: Print Print where +: = pBetween " +: "
+instance :+ Print Print where :+ = pBetween " :+ "
+instance :- Print Print where :- = pBetween " :- "
+instance *: Print Print where *: = pBetween " *: "
// -- Set expressions --
@@ -174,8 +177,8 @@ where
true = pr "true"
false = pr "false"
Not = surround "not (" ")"
- (||.) = \a b -> parens (between " ||. " a b)
- (&&.) = \a b -> parens (between " ||. " a b)
+ (||.) = pBetween " ||. "
+ (&&.) = pBetween " ||. "
instance Compare Print Print
where