16 ms·
Hmm, to me it seems that 'splitBy ","' should be a function that takes a string and returns a list of strings: splitBy "," : String -> List String so it see
by rstarast 6y ago
Hmm, to me it seems that 'splitBy ","' should be a function that takes a string and returns a list of strings:
splitBy "," : String -> List String
so it seems "clear" that the separator should be the first argument. But maybe I've just programmed functionally for too long?
As an alternative, perhaps there's space to introduce types to make this something like
split : Pattern -> String -> List String
- mrkeen 6y agoI agree with your intuition. I'll try to make my intuition explicit: The 'splittee' should be the last argument. The last argument is usually what you want to a) elide as part of function composition, or b) loop over (the tightest). E.g. Splitting a file into lines: lines content = splitBy "\n" content can be: lines = splitBy "\n" If splitBy used the other order, it would be: lines = (\c -> splitBy c "\n") E.g. Splitting a file by lines and tabs: entries content = concatMap splitBy "\t" (splitBy "\n" content) can be: entries = concatMap splitBy "\t" . splitBy "\n" If splitBy used the other order, it would be: entries content = concatMap splitBy (splitBy content "\n") "\t"
- a1369209993 6y agoI don't have a firm position on the matter, but consider: lines content = content .splitBy "\n" lines = (.splitBy "\n") dec x = x - 1 dec = (- 1) It seems like some infix-like things ought to be equivalent to (oper right left) rather than (oper left right). Not sure how that works out in practice, though.