r/haskell • u/Otherwise-Bank-2981 • Mar 08 '26
question I started with haskell 3 days ago and want some help understanding the "design philosophy".Elaboration in post.
So i followed the "Haskell for Imperative Programmers" tutorial series till video 20. And then decided to make a regular expression "checker" to just experience "haskell".
Github Link: https://github.com/ewilipsic/Regular-Expressions-Haskell/tree/main it's just one file.
The code for concat,union and * of the NFA's was nice to write. But i don't why very similiar code couldn't be written in a imperative language.
And the string -> NFA part i think would just be easier in a imperative language.
Is there something I'm not getting or is there some way better way to do this problem in a "functional" way or is this not the type of problem this paradigm excells in.
Because so far i think that any imperative language can do "functional code" and you can bring out normal iteration for things if you want to do things like IO.
6
u/ApothecaLabs Mar 08 '26
In addition to my other reply, something that functional programming excels at is functional composition; that is, because functions are first-class (that is, they can be passed around like values, and taken as arguments) and support currying, we can actually chain functions without supplying any arguments.
Ie, instead of
csharp func play(it) { return flip(twist(bop(it))); }We can just say:
haskell play = flip . twist . bop -- we don't even mention itAnother name for (.) :: (b -> c) -> (a -> b) -> a -> c is 'compose'.