Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. combining a trifecta parser with FreshMT from unbound
(Andreas Reuleaux)
----------------------------------------------------------------------
Message: 1
Date: Tue, 29 Jul 2014 00:26:17 +0100
From: Andreas Reuleaux <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] combining a trifecta parser with FreshMT
from unbound
Message-ID: <[email protected]>
Content-Type: text/plain
I can relatively easily combine a trifecta parser with some state:
-- imports, language pragmas omitted here
newtype InnerParser a = InnerParser { runInnerParser :: Parser a }
deriving (Functor
, Monad
, Applicative
, Alternative
, Parsing
, CharParsing
, MonadPlus
)
data PiState = PiState {
foobar :: Integer
-- ...some more stuff...
}
type PiParser = StateT PiState InnerParser
instance TokenParsing PiParser where
someSpace = buildSomeSpaceParser (skipSome (satisfy isSpace))
$ commentStart .~ "{-"
$ commentEnd .~ "-}"
$ commentLine .~ "--"
$ commentNesting .~ True
$ emptyCommentStyle
idStyle = styleStart .~ letter
$ styleLetter .~ (alphaNum <|> oneOf "_'")
$ styleReserved .~ HS.fromList
["refl"
,"ind"
,"Type"
-- ...
]
$ emptyIdents
identifier :: PiParser String
identifier = token
$ ident
$ idStyle
-- etc.
This is the approach taken in Idris e.g. and it works, as I understand,
because the trifecta/parsers type classes involved (CharParsing etc) are
"already
prepared" for attaching a StateT monad transformer: there are instances
defined for all the usual transformers: StateT, ReaderT, RWST etc.
I can easily add more convenient type classes, having them derived for
my InnerParser: LookAheadParsing, DeltaParsing etc.
Now when I want to use FreshMT from the unbound package instead of
StateT, things get much more complicated.
I don't really care at this point if with a type synonym
type PiParser = FreshMT InnerParser
or as a newtype wrapper (deriving as much as I can automatically)
newtype PiParser a = P {
runP :: FreshMT InnerParser a
} deriving (Monad, Functor, Applicative)
Anyway, I need to provide all these instances by hand (CharParsing,
Alternative etc), am still
struggling with the details (and might have more questions in this
regard), even though FreshMT really is just defined in terms of StateT
http://hackage.haskell.org/package/unbound-0.4.3.1/docs/src/Unbound-LocallyNameless-Fresh.html#FreshMT
So I wonder, if there is an easier way to approach this, have some more
instances derived automatically ?
(Basically I just want to get Stephanie Weirichs pi-forall language
working with trifecta instead of parsec, cf. this years' OPLSS)
I can provide complete running code (with all the imports etc) if
necessary.
Thanks.
-Andreas
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 73, Issue 20
*****************************************