Re:A philosophical difference between Haskell and Lisp (2015)
by Gajurgensen on Sunday August 02, 2020 @10:53PM
(#24033772)
Let's say getting those n and m values has a nasty type like `getNM :: IO (Maybe (Int, Int))`. All you need to do is map twice when using the original function.
foo (n, m) = take n . filter p . drop m
bar = fmap (fmap foo) getNM
It's a little awkward, but no major refactor. A small price to pay for the nice types we get. I'd argue that if other languages make dealing with IO and optional values easier, its because they don't bother restricting IO (not necessarily criticizing that), or they don't bother checking completeness over optionals (i.e. a stray `null` can show up anywhere and derail the program, which I do think is a bad thing). Overall, Haskell provides many powerful tools for composing complex types, such as the functor/applicative/monad classes.
Re:A philosophical difference between Haskell and Lisp (2015)
by chongli on Sunday August 02, 2020 @07:49PM
(#24032783)
keep the Maybe types from taking everything over.
Pattern matching on Maybe types is rather unidiomatic Haskell. Much better to take advantage of the type classes to which Maybe belongs: Functor, Applicative, Monad. In particular, there's no need to unwrap/wrap the Maybe value when you have `fmap`.
Re:A philosophical difference between Haskell and Lisp (2015)
by vore on Sunday August 02, 2020 @07:15PM
(#24032622)
Isn't that the exact same thing you would do in Haskell? How you read from a config file in Haskell seems irrelevant here, and troubles with it are more related to purity than composition.
dropNTakeM p n m = take m . filter p . drop n
Meanwhile in lisp I would have written a special drop3-take5 function in the first place. Then refactoring it would just take replacing 3 with n and 5 with m, adding n and m as arguments and writing a function to read whatever the config file is.