Skip to content

Commit

Permalink
added MonadPlus instance; fixed two warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dktr0 committed Dec 5, 2019
1 parent fc951ba commit 16fcfe1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Language/Haskellish.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Language.Haskellish where

import Language.Haskell.Exts
import Control.Applicative
import Control.Monad
import Data.Either (isRight)
import Data.Maybe (catMaybes)

Expand Down Expand Up @@ -48,6 +49,10 @@ instance Monad Haskellish where
runHaskellish (f x') e
)

instance MonadPlus Haskellish where
mzero = empty
mplus = (<|>)


identifier :: Haskellish String -- note: we don't distinguish between identifiers and symbols
identifier = Haskellish f
Expand Down Expand Up @@ -113,9 +118,9 @@ tuple p1 p2 = Haskellish (\e -> do
asRightSection :: Haskellish (a -> b -> c) -> Haskellish b -> Haskellish (a -> c)
asRightSection opP bP = Haskellish (\e -> do
(opExp,bExp) <- f e
op <- runHaskellish opP opExp
op' <- runHaskellish opP opExp
b <- runHaskellish bP bExp
return $ flip op b
return $ flip op' b
)
where
f (Paren _ x) = f x
Expand All @@ -129,6 +134,7 @@ collectDoStatements (Do _ xs) = catMaybes $ fmap f xs
where
f (Qualifier _ e) = Just e
f _ = Nothing
collectDoStatements _ = []

listOfDoStatements :: Haskellish a -> Haskellish [a]
listOfDoStatements p = Haskellish (\e -> mapM (runHaskellish p) $ collectDoStatements e)
Expand Down
2 changes: 1 addition & 1 deletion haskellish.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: haskellish
version: 0.1.0
version: 0.1.1
synopsis: For parsing Haskell-ish languages
homepage: http://github.com/dktr0/Haskellish
license: BSD3
Expand Down

0 comments on commit 16fcfe1

Please sign in to comment.