4 ms·
it's really neat, I love how easy it is to search for functions by type to find what you need. The one thing I ran into (as someone who only vaguely knows hask
by iamevn 5y ago
it's really neat, I love how easy it is to search for functions by type to find what you need.
The one thing I ran into (as someone who only vaguely knows haskell) is that it seems like it's impossible to write a function that takes a list of A or B as an argument and then branch on the type of each element. I can use Either but then I need to decorate each element in the list with Left/Right rather than just use their types.
This is probably just not how things work in Haskell and I just need to be okay with that.
- creata 5y ago> This is probably just not how things work in Haskell and I just need to be okay with that. Yep, that's just how things work in Haskell: disjoint unions are much simpler regular unions, and they're usually what you want in the first place. I think it'd be nice if Haskell had automatic conversions between types (so a and b can be turned into Either a b implicitly, with an error if a = b) but I don't think there are any plans for that.
- JackMorgan 5y agoPerhaps are you looking for Sum Types?[0] They let you group several types into a unifying type, e.g. a Shape is a Circle, Square, or Triangle, then you can use pattern matching to have different behavior for each. This example is in F# [1] but it's almost exactly the same as it would be in Haskell. [0]https://www.schoolofhaskell.com/user/Gabriel439/sum-types https://www.schoolofhaskell.com/user/Gabriel439/sum-types [1]http://deliberate-software.com/christmas-f-number-polymorphism/ http://deliberate-software.com/christmas-f-number-polymorphi...
- sullyj3 5y agoIf you could give a concrete example of a problem to be solved, I could try to convince you that the method using Either won't actually be all that unwieldy.