From 307919760c58e037ec3260fcd0c3c7f7227fd7aa Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 26 Feb 2024 22:59:54 +0100 Subject: WIP typecheck and other stuff --- src/Data/Bag.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/Data/Bag.hs (limited to 'src/Data/Bag.hs') diff --git a/src/Data/Bag.hs b/src/Data/Bag.hs new file mode 100644 index 0000000..9cdce89 --- /dev/null +++ b/src/Data/Bag.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE DeriveTraversable #-} +module Data.Bag where + + +data Bag a + = BTwo (Bag a) (Bag a) + | BOne a + | BZero + deriving (Functor, Foldable, Traversable) + +instance Semigroup (Bag a) where (<>) = BTwo +instance Monoid (Bag a) where mempty = BZero + +instance Applicative Bag where + pure = BOne + + BZero <*> _ = BZero + _ <*> BZero = BZero + BOne f <*> b = f <$> b + BTwo b1 b2 <*> b = BTwo (b1 <*> b) (b2 <*> b) -- cgit v1.2.3-70-g09d2