Send Beginners mailing list submissions to
        beginners@haskell.org

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
        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:  will GHC optimize pattern-matching on        integers?
      (Patrick Pelletier)


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

Message: 1
Date: Thu, 13 Apr 2017 19:11:31 -0700
From: Patrick Pelletier <c...@funwithsoftware.org>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] will GHC optimize pattern-matching on
        integers?
Message-ID: <a7be8316-d68e-64ca-f946-268d40fc0...@funwithsoftware.org>
Content-Type: text/plain; charset="utf-8"; Format="flowed"

Thanks!  That's exactly what I was hoping.

--Patrick


On 4/13/17 1:41 AM, Rahul Muttineni wrote:
> Hi Patrick,
>
> Yes, this will optimise to "a nice balanced tree of decisions with 
> dense jump tables in the leafs" [1]. You can check out the comments in 
> [1] for more details.
>
> [1] https://github.com/ghc/ghc/blob/master/compiler/cmm/CmmSwitch.hs#L37
>
> Hope that helps,
> Rahul
>
> On Thu, Apr 13, 2017 at 3:55 AM, Patrick Pelletier 
> <c...@funwithsoftware.org <mailto:c...@funwithsoftware.org>> wrote:
>
>     Suppose I am doing a pattern match on a large number of
>     consecutive (or mostly-consecutive) integers:
>
>     foo 0 = something
>     foo 1 = somethingElse
>     ...
>     foo 1000 = anotherThing
>
>     Will GHC optimize this to a table lookup, or is it going to test
>     each integer in turn?  Am I better off using a Vector or Map
>     instead of pattern matching?
>
>     Thanks,
>
>     --Patrick
>
>     _______________________________________________
>     Beginners mailing list
>     Beginners@haskell.org <mailto:Beginners@haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>     <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
>
>
>
>
> -- 
> Rahul Muttineni
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170413/22ef70f7/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 106, Issue 6
*****************************************

Reply via email to