[Haskell-cafe] How does one create an input handle bound to a string instead of a file?

Erik Hesselink hesselink at gmail.com
Thu Feb 28 15:00:25 CET 2013


Is your parser impure? I would expect a function from
String/Text/ByteString to Maybe (SExpr Pos).
 Then you have no need for a Handle.

Regards,

Erik

On Thu, Feb 28, 2013 at 2:32 PM, John D. Ramsdell <ramsdell0 at gmail.com> wrote:
> I think I wasn't clear about my question.  I want something that
> creates a value of type System.IO.Handle.  You see, I have a high
> performance S-expression parser that I'd like to use in GHCi reading
> strings while at the command loop.
>
> Here is more details on my module SExpr that exports the SExpr data
> type and the load function.  The desired function is called
> stringHandle.
>
> -- An S-expression
> data SExpr
>     = S String                 -- A symbol
>     | Q String                 -- A quoted string
>     | N Int                    -- An integer
>     | L [SExpr a]              -- A proper list
>
> -- Read one S-expression or return Nothing on EOF
> load :: Handle -> IO (Maybe (SExpr Pos))
>
> In GHCi, I want to type something like:
>
> SExpr> let h = stringHandle "()"
> SExpr> load h
> Just (L [])
> SExpr> load h
> Nothing
> SExpr>
>
> It seems to me right now that I have to implement a duplicate parser
> that implements Read.  At least S-expression parsing is easy.
>
> John
>
> On Thu, Feb 28, 2013 at 3:02 AM, Ganesh Sittampalam <ganesh at earth.li> wrote:
>> Hi,
>>
>> On 27/02/2013 20:38, John D. Ramsdell wrote:
>>> How does one create a value of type System.IO.Handle for reading that
>>> takes its input from a string instead of a file?  I'm looking for the
>>> equivalent of java.io.StringReader in Java.  Thanks in advance.
>>
>> http://hackage.haskell.org/package/bytestring-handle can make handles
>> that read and write to ByteStrings.
>>
>> Cheers,
>>
>> Ganesh
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list