<    March 2017    >
Su Mo Tu We Th Fr Sa  
          1  2  3  4  
 5  6  7  8  9 10 11  
12 13 14 15 16 17 18  
19 20 21 22 23 24 25  
26 27 28 29 30 31
00:04 gabriel-bezerra joined
00:14 uglyfigurine joined
00:19 Rizy joined
00:31 faberbrain joined
00:55 aarvar joined
01:05 pilne joined
01:23 MotherFlojo joined
01:32 Rizy joined
01:36 prophile joined
01:36 Pupnik joined
02:04 uglyfigurine joined
02:13 eacameron joined
02:20 \Mike joined
02:27 netheranthem joined
02:27 Heasummn joined
02:31 parsnip joined
02:33 argent0 joined
02:33 faberbrain joined
02:40 <argent0> Hello, I have a question about foldl. Concretely: How do I define foldl for `Snoc a = Nil | Snoc (Snoc a) a`? Is it? `foldl f (Snoc xs x) b = foldl f xs (b `f` x)`?
02:41 <argent0> why is it called a left-fold?
02:42 <argent0> EDIT: `foldl f (Snoc xs x) b = foldl f (b `f` x) xs`
02:42 <parsnip> argent0: it associates to the left, you'll also see initial object on the left
02:44 systemfault joined
02:45 <argent0> parsnip: ok, so for `Snoc a`, foldl is not a problem b.c. I can compute (b `f` x) and proced backtracking from the end of the `Snoc a`
02:45 <parsnip> argent0: here are some mnemonics for left vs right: http://notes.bradyt.com.s3-website-us-west-2.amazonaws.com/#sec-5-2
02:46 <ski> argent0 : i'd call that `foldr'
02:47 <ski> well, or almost
02:47 <ski> the argument ordering is a bit off
02:47 <ski> foldl (+) (Snoc (Snoc (Snoc Nil a) b) c) 0 = ((0 + c) + b) + a
02:48 <argent0> ski, yes the arguments are off: `foldl f b (Snoc cs x)` = foldl f (b `f` x) xs`
02:48 <ski> (a) the `b' argument is here the last one, rather than the structure being folded
02:48 <ski> (b) the arguments are passed to `f' in the opposite order to what would be expected with `foldr'
02:48 <ski> but apart from that, this is `foldr', not `foldl'
02:49 <argent0> parsnip: the link has odd type signatures for foldl and foldr. The types of `f` are reversed
02:50 <ski> flip (foldl (flip (+))) 0 (Snoc (Snoc (Snoc Nil a) b) c) = a + (b + (c + 0))
02:50 <argent0> ski, is `f :: (b -> a -> b)` righy
02:50 <argent0> ?
02:50 <ski> here we see more clearly that it corresponds closest to `foldr'
02:50 <parsnip> argent0: aha, you're right, will fix soon
02:51 <ski> argent0 : in your version, yes
02:52 <argent0> ski, I guess that is arbitrary. I'm following the types of the prelude's foldl function.
02:52 <argent0> ski, in a `Snoc as a` the last element would be `a` (right?), so it would be a left fold
02:53 <argent0> (is that correct?)
02:59 <argent0> parsnip: the implementations are right (afaict), the type anotations have been swiched
03:00 <argent0> s/anotations/signatures/g
03:06 <ski> argent0 : yes, the idea is to take the elements of the data structure, in the order they're given
03:06 <ski> for a real `foldl' for `Snoc', you'd have
03:07 <ski> foldl (+) (Snoc (Snoc (Snoc Nil a) b) c) 0 = ((0 + a) + b) + c -- which is not what your `foldl' above does
03:07 <* argent0> foldl f b xs `f` x
03:07 <argent0> ski, my version here is not right
03:07 <* ski> agrees
03:09 <argent0> but the new: `fold f b (Snoc xs x) = foldl f b xs `f` x` would yield: foldl (+) (Snoc (Snoc (Snoc Nil a) b) c) 0 = ((0 + a) + b) + c
03:09 <ski> yes
03:09 <ski> (of course you also need an appropriate base case .. but hopefully it is obvious)
03:10 <argent0> foldl b Nil = b --for the base case
03:10 uglyfigurine joined
03:10 <argent0> foldl _ b Nil = b --for the base case
03:10 <ski> yep
03:11 <* ski> . o O ( `(r -> r -> r) -> (a -> r) -> r -> [a] -> r' )
03:12 roboguy` joined
03:16 <argent0> so a fold being left/right depends on how it associates f. ((0+a)+b)+c or (a+(b+(c+0)). Ok, thanks for your help ski and parsnip. I hope I never forget about this :)
03:22 hexagoxel joined
03:22 eacameron joined
03:24 MotherFlojo joined
03:26 roboguy` joined
03:28 roboguy` joined
03:28 <ski> argent0 : yes
03:28 <ski> argent0 : now, define `foldl' and `foldr' for `data Tree a = Leaf a | Branch (Tree a) (Tree a)' ?
03:47 <argent0> ski: foldl f b (Branch l r) = let leftB = foldl f b l in foldl f leftB r
03:47 <argent0> ski: foldr f b (Branch l r) = let rightB = foldr f b r in foldr f rightB l
03:48 <argent0> base case: foldr f b (Leaf a) = f a b
03:48 wei2912 joined
03:48 <argent0> base case: foldl f b (Leaf a) = f b a
03:49 <ski> correct :)
03:49 <argent0> ski, thanks for the help
03:49 <ski> now, if you make variants of these, that take `b' as the last argument, then you could reformulate the definitions in an alternative, nice way
03:50 <ski> you could try to see what i mean, if you feel like
03:52 <argent0> you mean: `foldl :: Foldable t => (b -> a -> b) -> t a -> b`?
03:53 <argent0> or explicitely: `foldl :: Foldable t => (b -> a -> b) -> Tree a -> b`?
03:53 <* argent0> without the constrain
03:53 exferenceBot joined
03:54 <* argent0> and I left out a `-> b`
03:58 hexagoxel joined
04:01 <argent0> ski: magicFoldr f (Branch l r) = magicFoldr f l . magicFoldr f r
04:02 <argent0> magicFoldl f (Branch l r) = magicFoldl f r . magicFoldl f l
04:05 <argent0> both definitions are very similar. Is this what you meant?
04:05 <ski> yes, that :)
04:06 <ski> it's good to know about this way to view it, imho
04:07 <ski> instead of returning `b -> b', one could have it return `Endo b'
04:07 <ski> @src Endo
04:07 <lambdabot> newtype Endo a = Endo { appEndo :: a -> a }
04:07 <argent0> ski, I supouse this is due to the fact that left and right are very similar in a Tree. (I'll ponder this further). And now you are talking recursion schemes :)
04:07 <ski> which is an instance of `Monoid'
04:07 <ski> @type fold
04:07 <lambdabot> (Monoid m, Foldable t) => t m -> m
04:07 <ski> @type foldMap
04:07 <lambdabot> (Monoid m, Foldable t) => (a -> m) -> t a -> m
04:08 <ski> yes, i'm also alluding to `cata' a bit here
04:09 <ski> (`cata' is also sometimes known as "fold", but not in the sense of `Foldable'. it so happens that the catamorphism for `[]' is `foldr', though. while the catamorphism for your `Snoc' would be the `foldl' you defined for it)
04:11 <ski> one could ponder how to recover `foldl',`foldr' above, in terms of `foldMap' or `cata' (which shouldn't be that hard)
04:12 <ski> it might also be fun to write `foldl' and `foldr' for
04:12 <ski> @src Tree
04:12 <lambdabot> Source not found. Just try something else.
04:12 <ski> er, ok
04:12 <ski> data Tree a = Node a [Tree a]
04:12 <ski> (aka a "rose tree")
04:12 <ski> (and `fmap', if you feel like)
04:13 <argent0> yes, I'll try to write foldl in terms of foldMap
04:13 malaclyps joined
04:14 <argent0> Foldable only requires foldMap, I guess it implements foldl/r in terms of it, and this is the Monoid it uses
04:27 jtcs joined
04:32 mizu_no_oto_work joined
04:35 faberbrain joined
04:40 uglyfigurine joined
04:44 <argent0> magicFoldr' = magicFoldMap . (Endo .) --where magicFoldMap :: Monoid m => (a -> m) -> Tree a -> m. So this is how you get foldr/l from foldMap. I remember reading about Recursion Schemes, but I've both, forgoten and lost the code I wrote :)
04:44 <argent0> ski: ^^
04:46 <argent0> and with this new technology you only need to write foldMap for the rose tree
04:46 <ski> you need `appEndo' somewhere ..
04:47 <argent0> ski: yes I'm using `-> Endo b` like :magicFoldl' :: (b -> a -> b) -> Tree a -> Endo b
04:47 <argent0> so the appEndo would go at the begining
04:48 <ski> > First (Just 0) <> First (Just 1)
04:48 <lambdabot> First {getFirst = Just 0}
04:48 <ski> > Dual (First (Just 0)) <> Dual (First (Just 1))
04:48 <lambdabot> Dual {getDual = First {getFirst = Just 1}}
04:56 mac10688 joined
05:00 lithie joined
05:01 Pupnik_ joined
05:02 cschneid_ joined
05:11 NoCreativity joined
05:16 NoCreativity joined
05:17 uglyfigurine joined
05:17 hexagoxel joined
05:30 aniketd joined
05:35 hphuoc25 joined
05:38 mcspud joined
05:40 MotherFlojo joined
05:42 louispan joined
05:59 mcspud joined
06:08 mengu joined
06:11 uglyfigurine joined
06:13 hexagoxel joined
06:18 louispan joined
06:31 uglyfigurine joined
06:33 uglyfigu_ joined
06:36 faberbrain joined
06:58 hoffmeyer joined
07:18 hoffmeyer joined
07:35 Pupnik joined
07:39 hexagoxel joined
07:41 MotherFlojo joined
08:10 hexagoxel joined
08:14 Rizy joined
08:16 xmonader joined
08:20 dni- joined
08:24 cschneid_ joined
08:28 permegreen joined
08:29 inaba420 joined
08:32 zero_byte joined
08:36 MotherFlojo joined
08:38 hphuoc25 joined
08:38 faberbrain joined
08:41 t0by joined
08:41 t0by joined
08:41 Rizy joined
08:50 permagreen joined
08:55 simendsjo joined
08:55 wei2912 joined
08:57 merijn joined
09:04 owiecc joined
09:06 hexagoxel joined
09:18 uglyfigurine joined
09:20 madjestic joined
09:22 cschneid_ joined
09:23 hoffmeyer joined
09:27 prophile joined
09:31 mcspud joined
09:32 marmalod1 joined
09:35 albertus1 joined
09:43 louispan joined
09:58 thc202 joined
10:06 uglyfigurine joined
10:06 hoffmeyer joined
10:10 hexagoxel joined
10:13 EO_ joined
10:16 Rizy joined
10:30 louispan joined
10:33 louispan joined
10:38 louispan joined
10:40 faberbrain joined
10:41 hoffmeyer joined
10:51 g0d355__ joined
10:57 malaclyps joined
11:01 owiecc joined
11:11 nomotif joined
11:14 Rizy joined
11:19 nek0 joined
11:22 myrkraverk joined
11:23 gmg85 joined
11:39 Gurkenglas joined
11:45 MotherFlojo joined
11:57 <mounty> Is there a point-free way to write \(n, c) -> (n+1, c)
11:57 <mounty> I.e., take a pair and return the pair with the first component presumed to be a Num and incremented.
12:01 <mounty> Cancel that; just found http://pointfree.io
12:02 <zaquest> @pl \(n,c) -> (n+1,c)
12:02 <lambdabot> first (1 +)
12:03 <mounty> Yes but first doesn't appear to be in the standard prelude.
12:03 <zaquest> it isn't it's in Control.Arrow
12:03 <zaquest> @hoogle first
12:03 <lambdabot> Control.Arrow first :: Arrow a => a b c -> a (b, d) (c, d)
12:03 <lambdabot> Data.Bifunctor first :: Bifunctor p => (a -> b) -> p a c -> p b c
12:03 <lambdabot> Text.PrettyPrint.Annotated.HughesPJ first :: Doc a -> Doc a -> Doc a
12:08 <zaquest> well Data.Bifunctor.first works too
12:08 Pupnik_ joined
12:09 <zaquest> if Arrow is (->) and Bifunctor is tuple they are the same
12:14 <mounty> Thanks zaquest; that's working now.
12:17 hoffmeyer joined
12:21 Gurkenglas joined
12:34 janitor1 joined
12:40 dd09 joined
12:42 faberbrain joined
12:43 pie_ joined
12:43 pie_ joined
12:47 djfo joined
12:49 mimi_vx_ joined
12:51 ncyellow joined
12:52 mimi_vx_ joined
13:03 mimi_vx_ joined
13:05 stef204 joined
13:18 hoffmeyer joined
13:20 pilne joined
13:26 wei2912 joined
13:31 Rizy joined
13:35 Guest75127 joined
13:46 MotherFlojo joined
13:51 Rizy joined
13:53 ThomasLocke joined
13:54 teppic joined
14:18 hoffmeyer joined
14:19 keutoi joined
14:24 stef204 joined
14:39 Uniaika joined
14:44 faberbrain joined
14:53 grayjoc joined
14:55 Uniaika joined
15:03 Prutheus joined
15:03 eacameron joined
15:07 zero_byte joined
15:09 grayjoc joined
15:16 Prutheus joined
15:19 hoffmeyer joined
15:23 eacameron joined
15:43 hphuoc25 joined
15:47 MotherFlojo joined
15:59 Gurkenglas joined
16:04 \Mike joined
16:05 eacameron joined
16:08 owiecc joined
16:11 smichel17 joined
16:17 grayjoc joined
16:18 grayjoc joined
16:20 hoffmeyer joined
16:21 zero_byte joined
16:23 Deide joined
16:23 owiecc joined
16:24 grayjoc joined
16:29 grayjoc joined
16:36 mengu joined
16:37 keutoi joined
16:44 hphuoc25 joined
16:47 systemfault joined
16:47 grayjoc joined
16:49 eacameron joined
16:49 eacameron joined
16:52 albertus1 joined
16:54 zero_byte joined
17:00 janitor1 joined
17:08 ebsen joined
17:12 zero_byte joined
17:15 louispan joined
17:21 janitor1 joined
17:21 fhoffmeyer joined
17:21 hoffmeyer joined
17:28 owiecc joined
17:45 zero_byte joined
17:45 hphuoc25 joined
17:46 faberbrain joined
17:48 MotherFlojo joined
18:02 gk- joined
18:02 gk- left
18:07 meck_ joined
18:13 meck joined
18:15 prophile joined
18:22 hoffmeyer joined
18:36 nomotif joined
18:36 NoCreativity joined
18:37 gk-- joined
18:38 mac10688 joined
18:38 shayan_ joined
18:39 Gloomy joined
18:44 eacameron joined
18:48 faberbrain joined
19:09 owiecc joined
19:13 ncyellow left
19:19 Prutheus joined
19:22 hoffmeyer joined
19:32 wildlander joined
19:40 zero_byte joined
19:49 MotherFlojo joined
19:55 MotherFlojo joined
19:58 NoCreativity joined
20:03 brh joined
20:13 mac10688 joined
20:19 zero_byte joined
20:23 hoffmeyer joined
20:30 vmeson joined
20:33 grayjoc joined
20:39 smichel17 joined
20:46 seagreen joined
20:48 aarvar joined
20:49 faberbrain joined
20:56 Heasummn joined
20:59 grayjoc joined
21:03 MotherFlojo joined
21:06 eacameron joined
21:16 MotherFlojo joined
21:18 AndreasK joined
21:21 eacameron joined
21:23 Rodya_ joined
21:24 hoffmeyer joined
21:29 stef204 joined
21:35 zero_byte joined
21:45 eacameron joined
21:47 prophile joined
21:52 hiratara joined
21:52 argent0 joined
21:54 eacameron joined
21:56 Prutheus joined
21:57 <argent0> hi, is it possible to tell haskell that: instance (Foldable t, Foldable tt) => Foldable t tt?
21:57 <argent0> id est, if I have two nested foldables then I have a foldable. e.g: [[1],[1,2]]?
21:58 Guest4566 joined
21:59 <argent0> and then, for example: maximum [[1],[2,3]] = 3
22:00 <argent0> :t maximum
22:00 <lambdabot> (Foldable t, Ord a) => t a -> a
22:00 <monochrom> "Foldable t tt" does not make sense. After correcting it, the answer is still no.
22:00 Lazersmoke joined
22:02 louispan joined
22:03 <argent0> Ok, thanks. BTW, I was thinking about composing the types: t :: * -> * and tt :: * -> * so that (t tt) :: * -> *
22:05 <monochrom> There is a Compose type in Data.Functor.Compose (comes with recent GHC). You will write like "Compose [] []". It is going to be pretty verbose.
22:06 <monochrom> The good news, though, is that "instance (Foldable f, Foldable g) => Foldable (Compose * * f g)" is already done for you.
22:06 <monochrom> err delete the "* *" part.
22:07 <monochrom> (It's just Haddock reminding us of the kinds involved, in an intrusive way.)
22:07 <argent0> this is in Data.Functior.Compose that the instance is declared?
22:07 <monochrom> Yes.
22:07 <argent0> sorry, I have to go, Thanks for the help monochrom !
22:17 eacameron joined
22:21 roboguy` joined
22:25 hoffmeyer joined
22:31 hiratara joined
22:34 mounty joined
22:42 malaclyps joined
23:06 eacameron joined
23:06 louispan joined
23:09 AndiK joined
23:14 slo joined
23:16 eacameron joined
23:20 louispan joined
23:20 eacameron joined
23:23 Pupnik joined
23:25 hoffmeyer joined
23:28 eacameron joined
23:34 Gurkenglas_ joined
23:37 eacameron joined
23:42 carlomagno joined
23:51 faberbrain joined
23:55 contiver joined
23:58 louispan joined
23:58 madjestic joined