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. Re:  Data.Text to Int? (Tony Morris)


----------------------------------------------------------------------

Message: 1
Date: Sat, 15 Dec 2012 09:57:18 +1000
From: Tony Morris <[email protected]>
Subject: Re: [Haskell-beginners] Data.Text to Int?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Rather than filter isDigit then read, perhaps you might prefer mapMaybe.

On 15/12/12 01:19, Emmanuel Touzery wrote:
>
>>
>> An instance of Read means that read can *produce* a Text, not that it
>> can consume one.  read always reads from a String, as you can see
>> from its type:
>>
>>     Prelude Data.Text> :t read
>>     read :: Read a => String -> a
>>
>> (Note that it is the result type a in the context for Read.)
>
> yes, seeing the type signature I understood it. I was googling it
> without much luck, I didn't think of using ghci. I'll use that next time.
>
>> See the Data.Text.Read module (part of the text package you already
>> have installed) for how to do similar things with a Text as a source.
>>
>
> I see... However it uses Either and returns a pair, unlike "read".
> It's a plus for reliability but an annoyance in my case. In my case I
> know positively it's a number.
> In this case I did a filter isDigit, but this will happen also if I
> match using a regular expression and [0-9] or \d.
>
> In the end the most terse way to code it is to go through unpack then
> it seems.
> Using Data.Text.Read all I see is:
>
> fst $ right $ decimal t
> where right (Right a) = a
>
> so I'll probably do:
>
> read $ unpack t
>
> and be done with it...
>
> Thank you!
>
> emmanuel
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


-- 
Tony Morris
http://tmorris.net/




------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 54, Issue 21
*****************************************

Reply via email to