Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: using the joker "_" on a constructor (Kim-Ee Yeoh) 2. Re: using the joker "_" on a constructor (Christian Maeder) 3. Re: How to convert a float or double number into a string? (yi lu) 4. Re: How to convert a float or double number into a string? (yi lu) 5. Re: How to convert a float or double number into a string? (David McBride) ---------------------------------------------------------------------- Message: 1 Date: Wed, 18 Sep 2013 21:25:50 +0700 From: Kim-Ee Yeoh <k...@atamo.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] using the joker "_" on a constructor Message-ID: <CAPY+ZdTooRy4T8GaH_ADPTVeq1GdFWZfgjxzVScUrcG=8oq...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Wed, Sep 18, 2013 at 9:21 PM, Kim-Ee Yeoh <k...@atamo.com> wrote: > As to your original question why the underscore _ can't be overloaded for > this, I dunno. It /may/ be possible. Sorry, /possible/ means here in the context of hacking GHC etc to accommodate the syntax extension. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/135b14ce/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 18 Sep 2013 16:37:20 +0200 From: Christian Maeder <christian.mae...@dfki.de> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Cc: TP <paratribulati...@free.fr> Subject: Re: [Haskell-beginners] using the joker "_" on a constructor Message-ID: <5239baa0.1010...@dfki.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed In order to avoid your duplicate code consider to define "Foo" as follows: data Foo = F FB Int data FB = Foo | Bar f (F _ n) = even n and insert the constructor "F" after the final "$" in: > print $ f $ Bar 1 > print $ f $ Bar 2 > print $ f $ Foo 1 > print $ f $ Foo 2 HTH Christian Am 18.09.2013 16:08, schrieb TP: > Hi, > > I have a question about pattern matching. > Consider the following code: > > ------------------ > data Foo = Bar Int > | Foo Int > > f :: Foo -> Bool > f (Foo n) > | even n = True > | odd n = False > f (Bar n) > | even n = True > | odd n = False > > main = do > > print $ f $ Bar 1 > print $ f $ Bar 2 > print $ f $ Foo 1 > print $ f $ Foo 2 > ------------------ > > Why is it not possible to simply write for f: > > f v = case v of > _ n | even n -> True > _ n | odd n -> False > > or > > f (_ n) > | even n = True > | odd n = False > > (in both cases we get a parse error)? > > Thanks, > > TP > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > ------------------------------ Message: 3 Date: Wed, 18 Sep 2013 23:07:12 +0800 From: yi lu <zhiwudazhanjiang...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] How to convert a float or double number into a string? Message-ID: <CAKcmqqyCmD2yh-71A0kb2-cpzT3O7B5BRV6J=kryishf6of...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" You are right! I hope to input a number, for example 123, and output its text "one hundred and twenty-three". So, for 1.23456789012345678901, I want the result is "one point two three four five six ...(something omitted)". I can define a funciton, say "toText", to preform this action. In ghci, I can use like this. Prelude>toText 123.45 "one hundred and twenty-three point four five" However, in this function, I have to read this number as String(originally a number, now "123"), and make it to words(String) like "one two three". But for a float number, it will not work very well. Prelude>toText 1.23456789012345678901 "(a truncated answer)" This confuses me! Yi On Wed, Sep 18, 2013 at 10:23 PM, Oscar Benjamin <oscar.j.benja...@gmail.com > wrote: > > On Sep 18, 2013 2:15 PM, "yi lu" <zhiwudazhanjiang...@gmail.com> wrote: > > > > In fact, I am not looking for some way to convert a float 0.75 to 3%4. > Your reply is helpful! > > What I need is just as much number of digits as possible. If I can hold > as many digits of pi, i.e. 3.1415926535... as possible and save it in a > String, it will be perfect! > > I think something is still missing from your description. > > If you want to store the digits of pi in a string then why not use a > string? > > Oscar > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/23528c4f/attachment-0001.html> ------------------------------ Message: 4 Date: Wed, 18 Sep 2013 23:12:25 +0800 From: yi lu <zhiwudazhanjiang...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] How to convert a float or double number into a string? Message-ID: <CAKcmqqx_OMV_F8qUPCfQ5ZVyoxX2C=AmLaJmp=atjsWnye=v...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" This<https://github.com/eccstartup/numberToText/blob/master/src/Text/New/NumberToText.hs#L104>is my poor code. *show* function truncated these digits. On Wed, Sep 18, 2013 at 11:07 PM, yi lu <zhiwudazhanjiang...@gmail.com>wrote: > You are right! I hope to input a number, for example 123, and output its > text "one hundred and twenty-three". > So, for 1.23456789012345678901, I want the result is "one point two three > four five six ...(something omitted)". > I can define a funciton, say "toText", to preform this action. > In ghci, I can use like this. > Prelude>toText 123.45 > "one hundred and twenty-three point four five" > > However, in this function, I have to read this number as String(originally > a number, now "123"), and make it to words(String) like "one two three". > But for a float number, it will not work very well. > Prelude>toText 1.23456789012345678901 > "(a truncated answer)" > > This confuses me! > > Yi > > > On Wed, Sep 18, 2013 at 10:23 PM, Oscar Benjamin < > oscar.j.benja...@gmail.com> wrote: > >> >> On Sep 18, 2013 2:15 PM, "yi lu" <zhiwudazhanjiang...@gmail.com> wrote: >> > >> > In fact, I am not looking for some way to convert a float 0.75 to 3%4. >> Your reply is helpful! >> > What I need is just as much number of digits as possible. If I can hold >> as many digits of pi, i.e. 3.1415926535... as possible and save it in a >> String, it will be perfect! >> >> I think something is still missing from your description. >> >> If you want to store the digits of pi in a string then why not use a >> string? >> >> Oscar >> >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/a8f07c2e/attachment-0001.html> ------------------------------ Message: 5 Date: Wed, 18 Sep 2013 12:16:24 -0400 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] How to convert a float or double number into a string? Message-ID: <can+tr40ho7koptjpqxxusapb6eio5rvlsitngtrosrv2w52...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" Show is not truncating anything. Show never had those digits to read from in the first place. The problem is that once you convert to floats or doubles, the number will be truncated. They do not have infinite precision. You cannot pass a literal float and have it go to infinite precision. You have two options: You either pass the float as a string ie toText "1.23456" Or you use rationals toText ( 3.141591234567123123897192712937123987123987123 :: Rational) and do the arithmetic to change that into text 3141591234567123123897192712937123987123987123 % 1000000000000000000000000000000000000000000000 import Numeric import Data.Rational import GHC.Real let (num :% den) = fst $ head $ (readSigned readFloat) "3.141591234567123123897192712937123987123987123" :: Rational num -> 3141591234567123123897192712937123987123987123 den -> 1000000000000000000000000000000000000000000000 Then use the size of the denominator to figure out how far over to move the "point" in the first number. On Wed, Sep 18, 2013 at 11:12 AM, yi lu <zhiwudazhanjiang...@gmail.com>wrote: > This<https://github.com/eccstartup/numberToText/blob/master/src/Text/New/NumberToText.hs#L104>is > my poor code. > *show* function truncated these digits. > > > On Wed, Sep 18, 2013 at 11:07 PM, yi lu <zhiwudazhanjiang...@gmail.com>wrote: > >> You are right! I hope to input a number, for example 123, and output its >> text "one hundred and twenty-three". >> So, for 1.23456789012345678901, I want the result is "one point two three >> four five six ...(something omitted)". >> I can define a funciton, say "toText", to preform this action. >> In ghci, I can use like this. >> Prelude>toText 123.45 >> "one hundred and twenty-three point four five" >> >> However, in this function, I have to read this number as >> String(originally a number, now "123"), and make it to words(String) like >> "one two three". >> But for a float number, it will not work very well. >> Prelude>toText 1.23456789012345678901 >> "(a truncated answer)" >> >> This confuses me! >> >> Yi >> >> >> On Wed, Sep 18, 2013 at 10:23 PM, Oscar Benjamin < >> oscar.j.benja...@gmail.com> wrote: >> >>> >>> On Sep 18, 2013 2:15 PM, "yi lu" <zhiwudazhanjiang...@gmail.com> wrote: >>> > >>> > In fact, I am not looking for some way to convert a float 0.75 to 3%4. >>> Your reply is helpful! >>> > What I need is just as much number of digits as possible. If I can >>> hold as many digits of pi, i.e. 3.1415926535... as possible and save it in >>> a String, it will be perfect! >>> >>> I think something is still missing from your description. >>> >>> If you want to store the digits of pi in a string then why not use a >>> string? >>> >>> Oscar >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners@haskell.org >>> http://www.haskell.org/mailman/listinfo/beginners >>> >>> >> > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/6c62f34c/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 63, Issue 26 *****************************************