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. How to convert a float or double number into a string? (yi lu) 2. Re: Help getting glib installed (Britt Anderson) 3. Re: How to convert a float or double number into a string? (Oscar Benjamin) 4. Re: How to convert a float or double number into a string? (yi lu) 5. using the joker "_" on a constructor (TP) 6. Re: using the joker "_" on a constructor (Kim-Ee Yeoh) 7. Re: using the joker "_" on a constructor (David McBride) 8. Re: How to convert a float or double number into a string? (Oscar Benjamin) ---------------------------------------------------------------------- Message: 1 Date: Wed, 18 Sep 2013 20:48:57 +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: [Haskell-beginners] How to convert a float or double number into a string? Message-ID: <cakcmqqzr6ymxgvrhg6wexe0otxfj2ols5rje3c4s8s1b0t4...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" If I use `show`, show 123.45, it will return "123.45", a desired answer. However, for show 123.45678901234567890, it will return "123.45678901234568". I want to save all digits into a string. I suppose I use a wrong type of number, which is Float. But what can I do to work right? Yi PS: If you receive this mail twice, please ignore one of them. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/e7f80b0b/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 18 Sep 2013 08:50:20 -0400 From: Britt Anderson <britt.ander...@uwaterloo.ca> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Help getting glib installed Message-ID: <87wqmemgz7....@brittoffice.uwaterloo.ca> Content-Type: text/plain This suggestion worked well. glib installation problem [solved]. gte...@gmail.com writes: > Cabal-1.18 was released very recently and packages that have custom build > scripts are quite likely to be broken with it. > If you dont need any features that this version brings you should be good > with installing cabal-install-1.16.0.2 instead. > ------------------------------ Message: 3 Date: Wed, 18 Sep 2013 14:00:59 +0100 From: Oscar Benjamin <oscar.j.benja...@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: <CAHVvXxRa-scNMkY=-q5jdin+ng+1xr6edpeidycqtrgcofn...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On 18 September 2013 13:48, yi lu <zhiwudazhanjiang...@gmail.com> wrote: > If I use `show`, > show 123.45, it will return "123.45", a desired answer. > > However, for > show 123.45678901234567890, it will return > "123.45678901234568". > > I want to save all digits into a string. I suppose I use a wrong type of > number, which is Float. Yes, it is the wrong type of number. Float can only store finitely many digits and you're asking for slightly too many. Also even if it *looks like* float has enough digits for your number in fact it has converted them from decimal to binary. For non-integers exact decimal to binary conversion is rarely possible. In this case the nearest binary float is 123.4567890123456805895330035127699375152587890625 but many of these decimal digits will be truncated from display. > But what can I do to work right? Are rational numbers acceptable in your problem? http://stackoverflow.com/questions/7056791/how-to-parse-a-decimal-fraction-into-rational-in-haskell Oscar ------------------------------ Message: 4 Date: Wed, 18 Sep 2013 21:14:35 +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: <CAKcmqqz5y8jahMvd3xGLcQPOawDy5gkqTWcV80La=a6obeo...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 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! Yi On Wed, Sep 18, 2013 at 9:00 PM, Oscar Benjamin <oscar.j.benja...@gmail.com>wrote: > On 18 September 2013 13:48, yi lu <zhiwudazhanjiang...@gmail.com> wrote: > > If I use `show`, > > show 123.45, it will return "123.45", a desired answer. > > > > However, for > > show 123.45678901234567890, it will return > > "123.45678901234568". > > > > I want to save all digits into a string. I suppose I use a wrong type of > > number, which is Float. > > Yes, it is the wrong type of number. Float can only store finitely > many digits and you're asking for slightly too many. Also even if it > *looks like* float has enough digits for your number in fact it has > converted them from decimal to binary. For non-integers exact decimal > to binary conversion is rarely possible. In this case the nearest > binary float is 123.4567890123456805895330035127699375152587890625 but > many of these decimal digits will be truncated from display. > > > But what can I do to work right? > > Are rational numbers acceptable in your problem? > > http://stackoverflow.com/questions/7056791/how-to-parse-a-decimal-fraction-into-rational-in-haskell > > > 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/ecd8c012/attachment-0001.html> ------------------------------ Message: 5 Date: Wed, 18 Sep 2013 16:08:24 +0200 From: TP <paratribulati...@free.fr> To: beginners@haskell.org Subject: [Haskell-beginners] using the joker "_" on a constructor Message-ID: <onooga-c4g.ln1@rama.universe> Content-Type: text/plain; charset="ISO-8859-1" 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 ------------------------------ Message: 6 Date: Wed, 18 Sep 2013 21:21:47 +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+zdrnauytu0g8_escs6y-pmyxugj1jqnf0jurvycnszc...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" On Wed, Sep 18, 2013 at 9:08 PM, TP <paratribulati...@free.fr> wrote: > f :: Foo -> Bool > f (Foo n) > | even n = True > | odd n = False > f (Bar n) > | even n = True > | odd n = False > (1) Since even is monomorphized to Int -> Bool, you can just write f (Foo n) = even n f (Bar n) = even n (2) Since the sum subtypes are the same, you can write data Foo = Foo {myN :: Int} | Bar {myN :: Int} f :: Foo -> Bool f x = even $ myN x (3) As to your original question why the underscore _ can't be overloaded for this, I dunno. It /may/ be possible. Seems rare in practice. You could always apply the type isomorphism to get data FooT = Foo | Bar data Foo = Foo Int FooT f (Foo n _) = even n -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/28138c88/attachment-0001.html> ------------------------------ Message: 7 Date: Wed, 18 Sep 2013 10:22:27 -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] using the joker "_" on a constructor Message-ID: <CAN+Tr423fsaNvE+vZE9oyJ7wPzENsP=6f8dtw0z8t2+24jg...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" It has to know the constructor in order to know the type of n. In your case they are both int, but in the general case they could be completely different types and therefore you could not just use the constructors interchangeably. If you want to write this I would go: data Foo = Bar Int | Foo Int def unFoo (Bar n) = n def unFoo (Foo n) = n f v = if even (unFoo n) then True else False You could also define the data type as data Foo = Bar { unFoo :: Int } | Foo { unFoo :: Int } As long as you make sure unFoo works for every possibility (otherwise it would be a partial function that could throw an exception). On Wed, Sep 18, 2013 at 10:08 AM, TP <paratribulati...@free.fr> wrote: > 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 > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/861af809/attachment-0001.html> ------------------------------ Message: 8 Date: Wed, 18 Sep 2013 15:23:48 +0100 From: Oscar Benjamin <oscar.j.benja...@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: <cahvvxxsubgwdu-vedg9jt+z6jtl5f65ck5cxnckw1ny9q_a...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20130918/269d5fbb/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 25 *****************************************