[Haskell-beginners] will GHC optimize pattern-matching on integers?

Patrick Pelletier code at funwithsoftware.org
Wed Apr 12 22:25:10 UTC 2017


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



More information about the Beginners mailing list