Timeline for Is ad-hoc polymorphism a good practice in functional programming?
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 14, 2021 at 14:57 | comment | added | leftaroundabout |
...but that's not to say Haskell never needs to handle errors. Indeed one of the possibilities is Optional , which is called Maybe in Haskell. And you can always raise exceptions (Haskell is not total, in contrast to languages like Agda), but this should preferrably only be done if some IO operation failed that you couldn't possibly have planned for, or something truely “impossible” (so you thought) has happened.
|
|
Nov 14, 2021 at 14:50 | comment | added | leftaroundabout |
That's one of the advantage of the ABC sum type: it's not even possible to generate a value of a type that's not listed in the data declaration – you would need another constructor with type D -> ABC , but the only constructors are those that you've already listed. If you have a variable d :: D and try to write e.g. toX (Bee d) then you'll get a compiler error, which can never surface at runtime.
|
|
Nov 14, 2021 at 11:53 | comment | added | maaniB | awesome! I noticed you didn't raise errors, manually. How do FP langs like Haskell handle errors? Does Haskell return errors at runtime for an unknown type d? And What do you think about returning null types, in python we may return Union[x, None] or Optional[x] if we don't want to raise exceptions. | |
Nov 14, 2021 at 0:20 | history | edited | leftaroundabout | CC BY-SA 4.0 |
added 912 characters in body
|
Nov 14, 2021 at 0:10 | history | answered | leftaroundabout | CC BY-SA 4.0 |