Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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: best way to code this~~ (Alex Hammel)
2. Re: How to use trigonometric functions with Data.Scientific?
(David McBride)
3. Re: best way to code this~~ ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Tue, 02 Jun 2015 15:49:06 +0000
From: Alex Hammel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] best way to code this~~
Message-ID:
<CA+_xFepAMA0EbdC_R4C-LYXNa1w_=ubxqga3wzfropt7sfg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thank you so much for all the info ! Really appreciate it.
>
My pleasure!
however, i'm unclear why you didn't just use
>
> eithers = map (\x -> lookupEither (uppercase x) assocs) xs
>
> instead of mapping everything to uppercase first.
>
Two reasons:
1) I thought it would be slightly more readable.
2) There's no performance penalty.
My version looks like it traverses the list twice, but it doesn't because
laziness. Where the compiler for a strict language might make an
intermediate, uppercased list, Haskell will produce the uppercase values as
they are needed.
To prove that to myself, I ran a quick criterion
<https://hackage.haskell.org/package/criterion> benchmark. If anything,
inlining the call to uppercase *decreases* performance slightly.
Incidentally, that's the same reason why the `filterMap` function you asked
about earlier doesn't exist. You can just do `(map f . filter p) xs`. The
values will be created lazily, with no intermediate list.
>
> meanwhile i need to get with the list comprehension program. i use python
> list comprehensions all the time, and yet i continue to use map in haskell.
> how weird is that ?
>
Not super weird. In my experience listcomps (and their relatives) are much
more common in idiomatic Python than idiomatic Haskell.
Still something you'll want to know how to do, though. Think '|' = 'for',
'<-' = 'in' and ',' = 'if' and you'll be fine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150602/94c3af5d/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 2 Jun 2015 14:57:17 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to use trigonometric functions
with Data.Scientific?
Message-ID:
<can+tr40fafqt_xmf07qih+krsqfy8u3j_pom0ofymzugfpx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You should be able to use sin (toRealFloat a). But I imagine that could
introduce some error into your calculations. You will have to make sure
you put enough type signatures to infer Double.
On Tue, Jun 2, 2015 at 6:51 AM, Martin Vlk <[email protected]> wrote:
> Hi, I am writing a program to do some astronomical calculation, and I am
> using the Data.Scientific library to represent my floating point
> numbers. Would anyone know how to use trigonometric functions with the
> Scientific type?
>
> I see:
> a :: Scientific
> a = scientific 500036 (-5)
>
> sin :: Floating a => a -> a
>
> -- this won't work
> wrongType = sin a
>
> Any ideas?
>
> Many Thanks
> Martin
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150602/78dc737a/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 2 Jun 2015 21:53:04 -0700
From: <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] best way to code this~~
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Tue, 02 Jun 2015 15:49:06 +0000
Alex Hammel <[email protected]> wrote:
> My version looks like it traverses the list twice, but it doesn't because
> laziness. Where the compiler for a strict language might make an
> intermediate, uppercased list, Haskell will produce the uppercase values as
> they are needed.
ok that's cool to know. that's why i like going over these "simple" examples.
in thinking about my problem i realized that it's perfectly fine if the uneaten
list comes back upper case. so i went back to the map version. actually the
list comp version :-)
>
> Incidentally, that's the same reason why the `filterMap` function you asked
> about earlier doesn't exist. You can just do `(map f . filter p) xs`. The
> values will be created lazily, with no intermediate list.
precisely what i was wondering.
haven't tried out criterion yet, just installed it to try out.
seems like a valuable learning tool.
should be a good learning tool.
Brian
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 84, Issue 4
****************************************