Does GHC optimize functions that pattern match against a large number of 0 argument data constructors?

Viewed 47

Say I have a data type, with hundreds of data constructors:

data Goo 
  = Goo001
  | Goo002
  | Goo003
  ...
  | Goo999

and I make a function that pattern matches on every one of those constructors:

  func :: Goo -> Int
  func Goo001 = 78
  func Goo002 = 93
  func Goo003 = 789
  ...
  func Goo999 = 1

Does GHC optimize the different function equations in any way, so that to match Goo999, it doesn't have to try to match on all the previous 998 equations?

Or would it be better to make a Data.Map Goo Int and make func do a lookup on that map?

0 Answers
Related