On Mon, Dec 17, 2018 at 11:53 AM Jack Rosenthal <j...@rosenth.al> wrote: > > On Mon, 17 Dec 2018 at 07:58 -0800, Will Jukes wrote: > > After learning more Haskell I've been playing around with match and > > define/match, and I'm wondering if there's any particular reason to > > prefer more traditional Scheme forms over match (I vastly prefer match > > in most cases). Glancing at the match module it looks the process of > > expanding a match clause is pretty intricate, and the documentation > > mentions that match lacks the time complexity guarantee of case, but > > beyond that it's not immediately clear whether match imposes some > > unacceptable overhead or etc., or to what extent it does if so. > > You can always use "expand" or "expand-once" to look at the code > generated by the use of a match. Usually, it's just a bunch of nested > conds and lets, with a function and call to check the next pattern. > > Haskell's pattern matching is probably compiled to something more > efficient (anyone want to test this hypothesis?), but Racket's works > when you need it, and has some really nice features (e.g., list-no-order > and quasiquote matches).
One goal of the `match` library is that it generates code as good (performance-wise) as you could have written by hand. For almost everything, it achieves this goal (major exceptions include some hash table patterns and list-no-order, which is very hard to do efficiently in general). The implementation of `match` uses the same algorithms for compiling pattern matching as Haskell does, and performs some optimizations that I think GHC does not do. However, Haskell can implement some things more efficiently than Racket, in particular checking which kind of data something is, using a combination of static type information and algebraic data types. This is not a limitation of `match`, though -- any other Racket program you write will have the same limitations. Sam -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.