5 ms·
Yes, record accessors being partial functions is a big problem. One way to deal with this is to not use fields at all together with algebraic data types (i.e.
by pka 10y ago
Yes, record accessors being partial functions is a big problem.
One way to deal with this is to not use fields at all together with algebraic data types (i.e. when you have more than one constructor), just pattern match. When you have some common field across all constructors, define a regular function to pull it out:
someData :: MyData -> a
and use that instead. As to the second use case, if you need to access something common to A and B but not C, then:
someOtherData :: MyData -> Maybe a
and pattern match on that. Or first pattern match on C and then have a catch all _ for A and B.
lens remedies a lot of Haskell's pain points when it comes to records, but I have to say that PureScripts record system is so much nicer.
- maweki 10y agoLens is really cool but sadly it depends on ghci being available which immediately breaks ARM compatibility. :(
- dllthomas 10y ago> sadly it depends on ghci being available Do you mean Template Haskell? If so, I'm pretty sure it's not required for use, just to have the lenses defined for you. You can still define them manually, at the cost of a little extra boilerplate. If you actually mean ghci, then I have no idea what you're talking about...
- tome 10y agoI guess so, because Template Haskell is not available on ARM. But yes, then you can write out the lenses manually. EDIT: And this link ties Template Haskell to GHCi: http://stackoverflow.com/a/10929803 http://stackoverflow.com/a/10929803
- dllthomas 10y agoAh, good catch!
- dhess 10y agoI don't think it's true that Template Haskell isn't available on ARM, at least not with recent versions of GHC. Maybe what you're thinking of is the problem with cross-compiling and Template Haskell. Generally speaking, that does not work because Template Haskell can do evil platform-specific things at compile time, so if the host and target architectures don't match, you can run into problems. Anyway, you can use Template Haskell on ARM, you just have to compile it on ARM.