jgm / cheapskate

Experimental markdown processor in Haskell
BSD 3-Clause "New" or "Revised" License
107 stars 18 forks source link

Add `Generic` and `NFData` instances to Cheapskate types #19

Closed aisamanra closed 7 years ago

aisamanra commented 7 years ago

This is a small PR that adds a few more typeclass instances to the Cheapskate types. Unfortunately, those instances only make sense in GHC version 7.2 or later, so all these instances are guarded by CPP, and the extra dependency needed for deepseq is put behind a conditional in the Cabal file as well. This is some extra complexity, but still probably the simplest way of implementing these features while keeping backwards compatibility.

I'd be happy to expand on the motivation for this PR, but the short high-level description is that we're using cheapskate in another project—in particular, in the matterhorn chat client, where we need a Markdown parser that's reasonably fast and produces compact runtime structures—and it turns out that it'd help us to be able to force evaluation of the parsed structure immediately, and this would let us use deepseq on that parsed structure.

jgm commented 7 years ago

I have no problem with the addition of these instances, but I'd rather just give up support for GHC < 7.2 and dispense with the CPP complications. (For one thing I don't like the API to differ depending on the compiler version.)

By the way, cheapskate's Markdown parser has some issues. Did you consider using cmark-hs? Perhaps you want to avoid C code, which is understandable.

jgm commented 7 years ago

Thanks, I merged this manually.