Logs: freenode/#haskell
| 2020-11-19 11:13:20 | × | ft quits (~ft@shell.chaostreff-dortmund.de) (Ping timeout: 260 seconds) |
| 2020-11-19 11:13:48 | <dminuoso> | I tend to avoid ($) generally except for do blocks/lambdas (cant get myself to enable BlockArguments) |
| 2020-11-19 11:15:26 | <dminuoso> | In my opinion it's good to use function composition and parens. It gives you a better view on code structure |
| 2020-11-19 11:15:28 | <kuribas> | dminuoso: so do you write (f . g . h) x then? |
| 2020-11-19 11:16:03 | <dminuoso> | kuribas: Generally I favor `... f x where f = g . h . i` |
| 2020-11-19 11:16:21 | × | datajerk quits (~datajerk@sense.net) (Remote host closed the connection) |
| 2020-11-19 11:16:26 | kuribas | wonders if he writes everything infix his lisp colleages will like haskell more... |
| 2020-11-19 11:16:28 | <dminuoso> | but `f (g (h x))` is not bad either |
| 2020-11-19 11:16:35 | kuribas | means prefix |
| 2020-11-19 11:16:44 | <dminuoso> | It's somewhat situational |
| 2020-11-19 11:16:46 | → | datajerk joins (~datajerk@sense.net) |
| 2020-11-19 11:16:49 | <kuribas> | dminuoso: lispers agree :) |
| 2020-11-19 11:16:55 | <kuribas> | dminuoso: but clojurers not |
| 2020-11-19 11:17:12 | <zyklotomic> | ah i see |
| 2020-11-19 11:17:15 | <zyklotomic> | thanks for sharing |
| 2020-11-19 11:17:28 | <zyklotomic> | i've been generally writing (f . g . h) x too |
| 2020-11-19 11:17:37 | <zyklotomic> | and $ felt a bit unnatural at first |
| 2020-11-19 11:17:54 | <kuribas> | clojurers write (-> x h g f). IMO it's strictly worse than ($) or (.), as it is a syntactic, rather than semantic construct. |
| 2020-11-19 11:18:30 | <dminuoso> | zyklotomic: Using function composition brings functions as first class objects more into view |
| 2020-11-19 11:18:43 | <dminuoso> | Say `fmap (f . g) ...` |
| 2020-11-19 11:18:51 | <kuribas> | zyklotomic: I think the reasoning behidn . . . $ is that if you remove the last argument it still works. |
| 2020-11-19 11:19:14 | <dminuoso> | (You could call this "point-free", but often its useful to think of functions as pipelines you can just compose to do more complex things) |
| 2020-11-19 11:19:15 | <boxscape> | dminuoso Refl example: https://gist.github.com/JakobBruenker/38251269a93cdd1f4979b771e613f4e6 |
| 2020-11-19 11:19:18 | <kuribas> | zyklotomic: f x = g . h $ x => f = g . h |
| 2020-11-19 11:19:20 | <zyklotomic> | yeah, i do `fmap (f . g)` too |
| 2020-11-19 11:19:44 | <zyklotomic> | like the other pattern i've seen that parallels this, is f <*> g <$> h |
| 2020-11-19 11:19:47 | <kuribas> | zyklotomic: but with f x = g $ h $ x you have to replace all the ($)'s |
| 2020-11-19 11:19:50 | <zyklotomic> | which well it does make sense |
| 2020-11-19 11:20:17 | <boxscape> | dminuoso in the pattern guards the equality constraint is extracted |
| 2020-11-19 11:20:25 | <dminuoso> | zyklotomic: If you explore this much, there's some pretty cool tricks |
| 2020-11-19 11:20:31 | <kuribas> | zyklotomic: in the end it's your own preference |
| 2020-11-19 11:20:33 | <dminuoso> | Personally Im a big fan of foldMap for example |
| 2020-11-19 11:20:45 | × | alp quits (~alp@2a01:e0a:58b:4920:6cd6:5f96:4d6d:5a5) (Ping timeout: 272 seconds) |
| 2020-11-19 11:20:45 | <zyklotomic> | dminuoso: wait, I finally see exactly what you mean about the last argument now |
| 2020-11-19 11:20:53 | <zyklotomic> | I never came upon that realization |
| 2020-11-19 11:21:13 | <dminuoso> | % getSum . foldMap Sum $ [1,2,3,4] :: Integer |
| 2020-11-19 11:21:14 | <yahb> | dminuoso: 10 |
| 2020-11-19 11:21:14 | <zyklotomic> | it was always trying to work out the order of operations/priority of the operetors idk what it's called |
| 2020-11-19 11:21:19 | <zyklotomic> | precedence? |
| 2020-11-19 11:21:43 | <zyklotomic> | like the PEMDAS of operators, i'm not sure what to calli t |
| 2020-11-19 11:22:06 | <dminuoso> | boxscape: Okay, so Im staring at this, my head is not quite ready to be contorted. |
| 2020-11-19 11:22:16 | <dminuoso> | Superficially, I can read it and understand what this is doing |
| 2020-11-19 11:22:23 | <dminuoso> | But not quite why this works inductively |
| 2020-11-19 11:22:40 | × | pfurla_ quits (~pfurla@ool-182ed2e2.dyn.optonline.net) (Ping timeout: 260 seconds) |
| 2020-11-19 11:22:40 | <dminuoso> | Is this essentially a theorem prover like coq in action? |
| 2020-11-19 11:23:00 | <boxscape> | dminuoso yes, the main difference being that we can't be sure they're actually proofs because the totality checker is missing |
| 2020-11-19 11:23:01 | → | alp joins (~alp@2a01:e0a:58b:4920:7900:a63:b56e:5a9) |
| 2020-11-19 11:23:15 | <boxscape> | (though if a proof terminates successfully for an input, you've proven it for that input) |
| 2020-11-19 11:23:20 | <dminuoso> | boxscape: Oh you mean because I can just sneak `undefined` in at any point to prove whatever? |
| 2020-11-19 11:23:24 | <boxscape> | right |
| 2020-11-19 11:23:55 | <kuribas> | dminuoso: how is that better than foldr (+) 0 [1, 2, 3, 4] ? |
| 2020-11-19 11:24:23 | <dminuoso> | kuribas: Sum carries monoid laws implictly |
| 2020-11-19 11:24:23 | × | jpds quits (~jpds@gateway/tor-sasl/jpds) (Ping timeout: 240 seconds) |
| 2020-11-19 11:24:32 | <boxscape> | dminuoso tbh these kinds of proofs are a lot easier to understand while writing than while reading, because you can look at the hole types along the way |
| 2020-11-19 11:24:33 | <dminuoso> | with foldr you cant reason about laws |
| 2020-11-19 11:24:43 | → | pfurla joins (~pfurla@190.15.195.173.client.static.strong-in52.as13926.net) |
| 2020-11-19 11:25:01 | <dminuoso> | say, will `foldr (+) 0 [1,2,3,4]` and `foldl (+) 0 [1,2,3,4]` do the same thing? |
| 2020-11-19 11:25:12 | <dminuoso> | Dunno really |
| 2020-11-19 11:25:44 | <dminuoso> | I mean for this case I can of course tell, but the associativity and identity is not clearly communicated, and it's extra verbose |
| 2020-11-19 11:25:48 | <kuribas> | dminuoso: depends on the Num instance |
| 2020-11-19 11:25:59 | → | jpds joins (~jpds@gateway/tor-sasl/jpds) |
| 2020-11-19 11:26:00 | <dminuoso> | kuribas: Im just very fond of traverse and foldMap |
| 2020-11-19 11:26:08 | <boxscape> | for example `plus_Z (SS n) = _` has hole type `'S (Plus n1 'Z) :~: 'S n1`, so we can call plus_Z n recursively and match on that to get out the `Plus n1 Z ~ n1` constraint, and then we just have to make something of type `S n1 :~: S n1`, which is Refl |
| 2020-11-19 11:26:09 | <kuribas> | also foldMap Sum is very ineffecient |
| 2020-11-19 11:26:20 | <kuribas> | it's too lazy |
| 2020-11-19 11:26:46 | <dminuoso> | Often efficiency is not a problem I need, expressivity is more important to me :) |
| 2020-11-19 11:27:01 | <dminuoso> | Consider this trick to implement traverse: |
| 2020-11-19 11:27:04 | <kuribas> | I prefer both |
| 2020-11-19 11:27:11 | × | sdx23 quits (~sdx23@unaffiliated/sdx23) (Remote host closed the connection) |
| 2020-11-19 11:27:16 | × | olligobber quits (olligobber@gateway/vpn/privateinternetaccess/olligobber) (Ping timeout: 240 seconds) |
| 2020-11-19 11:27:20 | <kuribas> | I mean efficiency and expressivity are not necessary mutually exclusive |
| 2020-11-19 11:27:26 | → | sdx23 joins (~sdx23@unaffiliated/sdx23) |
| 2020-11-19 11:27:30 | <dminuoso> | % ala ZipList traverse [[1,2,3],[10,20,30],[100,200,300]] |
| 2020-11-19 11:27:30 | <yahb> | dminuoso: ; <interactive>:32:1: warning: [-Wtype-defaults]; * Defaulting the following constraints to type `Integer'; (Show b0) arising from a use of `print' at <interactive>:32:1-55; (Num b0) arising from a use of `it' at <interactive>:32:1-55; * In a stmt of an interactive GHCi command: print it; [[1,10,100],[2,20,200],[3,30,300]] |
| 2020-11-19 11:27:39 | <dminuoso> | % ala ZipList traverse [[1,2,3],[10,20,30],[100,200,300]] :: [[Integer]] |
| 2020-11-19 11:27:40 | <yahb> | dminuoso: [[1,10,100],[2,20,200],[3,30,300]] |
| 2020-11-19 11:28:02 | <dminuoso> | Can't deny there's a certain beauty of both foldMap and traverse :) |
| 2020-11-19 11:28:38 | <dminuoso> | kuribas: Also, we have foldMap' now :p |
| 2020-11-19 11:29:07 | <dminuoso> | % ala Product foldMap [1,2,3,4] |
| 2020-11-19 11:29:07 | <yahb> | dminuoso: ; <interactive>:34:1: warning: [-Wtype-defaults]; * Defaulting the following constraints to type `Integer'; (Show a0) arising from a use of `print' at <interactive>:34:1-29; (Num a0) arising from a use of `it' at <interactive>:34:1-29; * In a stmt of an interactive GHCi command: print it; 24 |
| 2020-11-19 11:29:27 | <dminuoso> | % ala Product foldMap [1,2,3,4] |
| 2020-11-19 11:29:28 | <yahb> | dminuoso: 24 |
| 2020-11-19 11:29:30 | <kuribas> | foldMap' evaluated from left? |
| 2020-11-19 11:29:44 | <dminuoso> | foldMap' f = foldl' (\ acc a -> acc <> f a) mempty |
| 2020-11-19 11:29:52 | <dminuoso> | foldMap f = foldr (mappend . f) mempty |
| 2020-11-19 11:29:56 | <kuribas> | ah cool |
| 2020-11-19 11:30:20 | <nshepperd> | i presume foldMap' is strictly evaluated in whatever direction makes most sense for the type? |
| 2020-11-19 11:30:52 | <kuribas> | nshepperd: is that even possible? |
| 2020-11-19 11:31:06 | <kuribas> | nshepperd: ah by type you mean the foldable? |
| 2020-11-19 11:31:21 | <nshepperd> | ie. foldl' for lists, foldr' for snoc lists |
| 2020-11-19 11:31:24 | <nshepperd> | yeah |
| 2020-11-19 11:33:40 | → | berberman_ joins (~berberman@unaffiliated/berberman) |
| 2020-11-19 11:34:41 | × | berberman quits (~berberman@unaffiliated/berberman) (Ping timeout: 272 seconds) |
| 2020-11-19 11:35:47 | → | chalkmonster joins (~chalkmons@unaffiliated/chalkmonster) |
| 2020-11-19 11:36:31 | <dminuoso> | what is a snoc list? |
| 2020-11-19 11:37:04 | <pjb> | A list from the end? |
| 2020-11-19 11:37:24 | <dminuoso> | And that is different from a list... how? |
| 2020-11-19 11:37:54 | <boxscape> | I guess it's different in that foldl has been renamed to foldr and vice versa? |
| 2020-11-19 11:38:36 | <dminuoso> | boxscape: How's that? |
| 2020-11-19 11:38:46 | <dminuoso> | The difference between foldl and foldr is not the order of the lits |
All times are in UTC.