Closed Munksgaard closed 4 years ago
Also, it would be nice with instances for a few more tuple-lengths.
In practice I often end up not using the SexpIso
class at all since the default Bool
instance or Maybe
instance is not what I want in that particular case. This is why I was even thinking of removing SexpIso
class from the next major version. But if the class is useful, adding instances for tuples of length 0 to 9 makes a lot of sense. (Also, probably for many other types.)
Aha, so you write custom isomorphisms for everything?
For the record, I've just started using sexp-grammar, but I'm trying to create an isomorphism for the intermediate representation language (IR) in Futhark. If you're interested, you can see my progress here. As you can see, I tend to use the the SexpIso
class quite a lot, but perhaps there's a better way? To be honest, I haven't even completed my translation yet, so it's very likely that I run into some unforeseen issues with my method once I start trying to translate some real Futhark programs.
I think, for some types it makes sense. For others it probably does not. It's like having a Monoid
instance for Int
-- you have to arbitrarily choose whether it is an additive monoid you're interested in, or maybe multiplicative, or perhaps even with bitwise OR operation and 0 as a neutral element. If there is (or should be) only one way of writing SexpIso
than I would say, it makes sense to have the instance. If the instance seems arbitrary, I'd say it's better to keep bare functions.
One of the modules where I mostly use functions: Sugared.hs
Btw, since you're implementing a grammar for a pretty large AST, I'd love to hear some feedback on the user experience side of using the library. I know, this match $ With ...
pattern can be pretty frustrating because it's positional. And also not having a proper vocabulary of stack manipulation combinators is also sometimes limiting (however it is rather easy to fix).
Of course! I'll try to write up something once I have a more complete grammar :+1:
Please give it a try. (See 756503b1)
Excellent! I'll take a look tomorrow :+1:
Please give it a try. (See 756503b1)
That's perfect! I can get rid of a few orphan instances now...
Could you release a new version with these changes included, or are thinking about doing that larger refactoring first? Also, I promise I'll get around to writing about my experience with sexp-grammar, but probably not until later this week.
Yes, that's a good idea. I'll probably release a minor version later today.
No worries about the experience write-up.
Would it make sense to add an instance for
()
? It could be()
ornil
.