Skip to content

Commit

Permalink
Add comment clarifying usage of Primer.Core.DSL.bool_ etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
georgefst authored and dhess committed Jan 31, 2022
1 parent 1f6da73 commit 9ada783
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions primer/src/Primer/Core/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,6 @@ branch c vs e = CaseBranch c <$> mapM binding vs <*> e
char :: MonadFresh ID m => Char -> m Expr
char c = PrimCon <$> meta <*> pure (PrimChar c)

bool_ :: MonadFresh ID m => Bool -> m Expr
bool_ b = con $ if b then "True" else "False"

nat :: MonadFresh ID m => Natural -> m Expr
nat = \case
0 -> con "Zero"
n -> app (con "Succ") $ nat (n - 1)

maybe_ :: MonadFresh ID m => m Type -> (a -> m Expr) -> Maybe a -> m Expr
maybe_ t f = \case
Nothing -> con "Nothing" `aPP` t
Just x -> con "Just" `aPP` t `app` f x

tEmptyHole :: MonadFresh ID m => m Type
tEmptyHole = TEmptyHole <$> meta

Expand All @@ -163,3 +150,15 @@ meta = meta' Nothing

meta' :: MonadFresh ID m => a -> m (Meta a)
meta' a = Meta <$> fresh <*> pure a <*> pure Nothing

-- These functions rely on particular types being in scope.
bool_ :: MonadFresh ID m => Bool -> m Expr
bool_ b = con $ if b then "True" else "False"
nat :: MonadFresh ID m => Natural -> m Expr
nat = \case
0 -> con "Zero"
n -> app (con "Succ") $ nat (n - 1)
maybe_ :: MonadFresh ID m => m Type -> (a -> m Expr) -> Maybe a -> m Expr
maybe_ t f = \case
Nothing -> con "Nothing" `aPP` t
Just x -> con "Just" `aPP` t `app` f x

0 comments on commit 9ada783

Please sign in to comment.