parsing types

Daniel Peebles pumpkingod at gmail.com
Sat Apr 23 20:54:42 CEST 2011


I don't have an answer for you, but you might want to look at what :k does
in ghci, since that needs to parse a type.

On Sat, Apr 23, 2011 at 2:06 PM, Ranjit Jhala <jhala at cs.ucsd.edu> wrote:

> Hi all,
>
> can someone give me a hint as to the best way to parse a type from a
> string.
> Ideally, I'd like a function
>
>        stringType :: String -> Maybe Type
>
> or possibly,
>
>        stringType :: (GhcMonad m) => String -> m (Maybe Type)
>
> such that,
>
>        stringType s == Just t
>
> if in the current GHC context the string s is the name of the type t. For
> example, I'd like:
>
>        stringType "Int"
>
> to return a value equal to intTy (from TysWiredIn). My investigations have
> led me to
>
>        parseType :: P (LHsType RdrName)
>
> and I suspect that with some work (mainly creating an appropriate PState,
> and mapping the name back, I can extract what I want, but I was wondering
> if there is some simpler route that I've overlooked.
>
> Thanks!
>
> Ranjit.
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20110423/e7455bc2/attachment.htm>


More information about the Glasgow-haskell-users mailing list