3 ms·
So instead of having a .push method that takes a list of two arguments, I have a Cons2 constructor that takes two arguments... groundbreaking. If the Haskell m
by jakear 6y ago
So instead of having a .push method that takes a list of two arguments, I have a Cons2 constructor that takes two arguments... groundbreaking.
If the Haskell method gave you iterability for free I could see the benefit, but it doesn’t.
- lexi-lambda 6y agoIt actually does, though I didn’t mention it in the blog post. Here’s how you write it: data EvenList a = EvenNil | EvenCons a a (EvenList a) deriving (Functor, Foldable, Traversable) But that isn’t really the point of the example. As the blog post itself points out, it’s likely more useful to use a list of pairs in most situations, and that choice would still be a constructive representation. The example is not about exactly the way you choose to represent the property in question. The example is a demonstration that it’s possible to capture these properties using your type system even if it doesn’t have any first-class support for constraining list types this way. You can choose whichever representation you like the most/is most natural in your language of choice, of course, and you should! The blog post is just pointing out that you shouldn’t give up altogether on being able to capture these properties without changing the type system itself.