Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2020-11-20 08:12:55 cloudster joins (~cloudster@124.123.105.47)
2020-11-20 08:13:15 × cloudster quits (~cloudster@124.123.105.47) (Remote host closed the connection)
2020-11-20 08:13:19 alp joins (~alp@2a01:e0a:58b:4920:c533:3fa3:3963:3f02)
2020-11-20 08:13:32 jonatanb joins (jonatanb@gateway/vpn/protonvpn/jonatanb)
2020-11-20 08:14:41 × star_cloud quits (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com) (Remote host closed the connection)
2020-11-20 08:14:44 cloudster joins (~cloudster@124.123.105.47)
2020-11-20 08:14:58 × plutoniix quits (~q@ppp-223-24-158-101.revip6.asianet.co.th) (Ping timeout: 260 seconds)
2020-11-20 08:15:30 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 272 seconds)
2020-11-20 08:16:36 mikevdg joins (73bd5248@115-189-82-72.mobile.spark.co.nz)
2020-11-20 08:17:36 <mikevdg> I've got a Monad question regarding https://github.com/opqdonut/haskell-exercises/blob/master/templ/W6B.hs
2020-11-20 08:17:50 <mikevdg> Excuse the CCPP stuff in that file. Line 676
2020-11-20 08:17:55 <mikevdg> *CPP
2020-11-20 08:18:24 <mikevdg> you have `where g state = let (v, state1, log) = runSL op state0`
2020-11-20 08:18:48 <mikevdg> How is that possible? How can you say `where f x = ...` if x doesn't have a value?
2020-11-20 08:19:05 <mikevdg> I understand you can do it for pattern matching with tuples and lists. (a, b) = f x...
2020-11-20 08:19:17 <mikevdg> But is that possible with functions too?
2020-11-20 08:19:40 <mikevdg> (g is (Int -> (a, Int, [String])
2020-11-20 08:21:13 × drbean quits (~drbean@TC210-63-209-219.static.apol.com.tw) (Ping timeout: 264 seconds)
2020-11-20 08:22:57 <koz_> mikevdg: 'where g state = ...' is basically 'where g = \state -> ...'.
2020-11-20 08:23:02 <koz_> Is that what threw you?
2020-11-20 08:23:08 <merijn> mikevdg: That's just defining a function
2020-11-20 08:23:21 × cloudster quits (~cloudster@124.123.105.47) (Remote host closed the connection)
2020-11-20 08:23:23 <mikevdg> I've been staring at this exercise for an hour.
2020-11-20 08:23:51 <merijn> "where f x = ..." is just "defining a local function 'f' with a single argument 'x'"
2020-11-20 08:24:08 <mikevdg> yea, that makes sense now. Now that I think about it, I do it all the time.
2020-11-20 08:24:13 <mikevdg> double x = x * x
2020-11-20 08:24:29 <koz_> mikevdg: Yeah - you can write that as 'double = \x -> x * x'
2020-11-20 08:24:35 <mikevdg> f x = ... where f is some anonymous function... same pattern.
2020-11-20 08:24:57 <mikevdg> well... it's not anonymous if you call it f.
2020-11-20 08:25:02 star_cloud joins (~star_clou@ec2-34-220-44-120.us-west-2.compute.amazonaws.com)
2020-11-20 08:25:22 <mikevdg> foo = MyMonad f where f arg = ...
2020-11-20 08:26:54 <mikevdg> It threw me because I was defining a function that was being used as a variable.
2020-11-20 08:27:18 plutoniix joins (~q@node-ufe.pool-125-24.dynamic.totinternet.net)
2020-11-20 08:27:20 × Fractalis quits (~Fractalis@2601:987:280:8d40:9de1:6445:b757:a1c4) (Quit: Leaving)
2020-11-20 08:28:29 <mikevdg> you guys are awesome.
2020-11-20 08:28:42 <koz_> mikevdg: We try.
2020-11-20 08:31:51 borne joins (~fritjof@200116b86455d000f1dc39039d201adf.dip.versatel-1u1.de)
2020-11-20 08:31:52 <opqdonut> mikevdg: I hope you like the exercises! Check out https://haskell.mooc.fi which is based on the same exercises, but also contains reading material
2020-11-20 08:32:09 <merijn> mikevdg: Well, technically it *is* defining a variable. It's just a variable that happens to be a function :)
2020-11-20 08:32:13 <mikevdg> hey, it's the author! Sure, will do.
2020-11-20 08:32:15 <opqdonut> mikevdg: part 1 is out, but it doesn't cover monads, part 2 will come soon(tm)
2020-11-20 08:33:11 <guest1120> what's diffrent with <|> and >> ?
2020-11-20 08:33:19 <merijn> guest1120: Eh, lots :p
2020-11-20 08:33:30 <guest1120> simply?
2020-11-20 08:33:47 <[exa]> guest1120: if you asked for *> and >> the answer would be simple, but <|> and >> differ even in type signature
2020-11-20 08:33:49 <koz_> :t (<|>)
2020-11-20 08:33:50 <lambdabot> Alternative f => f a -> f a -> f a
2020-11-20 08:33:54 <koz_> :t (>>)
2020-11-20 08:33:55 <lambdabot> Monad m => m a -> m b -> m b
2020-11-20 08:33:58 <koz_> Simply. :P
2020-11-20 08:33:58 <merijn> guest1120: <|> is a choice combinator, exact meaning but in, for example, parsers it's usually "left *or* right"
2020-11-20 08:33:59 cloudster joins (~cloudster@124.123.105.47)
2020-11-20 08:34:25 <merijn> > Just 2 <|> Just 3
2020-11-20 08:34:27 <lambdabot> Just 2
2020-11-20 08:34:34 <merijn> > Nothing <|> Just 3
2020-11-20 08:34:36 <lambdabot> Just 3
2020-11-20 08:34:40 <merijn> > Just 2 >> Just 3
2020-11-20 08:34:42 <lambdabot> Just 3
2020-11-20 08:34:46 × cloudster quits (~cloudster@124.123.105.47) (Remote host closed the connection)
2020-11-20 08:34:46 <guest1120> ok
2020-11-20 08:34:46 <merijn> > Nothing >> Just 3
2020-11-20 08:34:48 <lambdabot> Nothing
2020-11-20 08:34:58 <dminuoso> guest1120: Note that the "or" should be taken with a grain of salt.
2020-11-20 08:35:00 kritzefitz joins (~kritzefit@fw-front.credativ.com)
2020-11-20 08:36:55 <merijn> Yes
2020-11-20 08:37:03 <merijn> > [1,2] >> [3,4]
2020-11-20 08:37:05 <lambdabot> [3,4,3,4]
2020-11-20 08:37:10 <merijn> > [1,2] <|> [3,4]
2020-11-20 08:37:12 <lambdabot> [1,2,3,4]
2020-11-20 08:37:29 <guest1120> what?
2020-11-20 08:37:32 <koz_> merijn: I had never considered >> in a list context before.
2020-11-20 08:38:11 <merijn> koz_: :)
2020-11-20 08:38:15 <dminuoso> guest1120: Roughly, if you build a parser: `string "foobar" <|> string "fooquux"` and throw it against "fooquux" then depending on the parser library it might not parse.
2020-11-20 08:38:41 <koz_> Like, upon thought it makes sense, but I guess I hardly ever use lists for their monad properties.
2020-11-20 08:39:02 <merijn> guest1120: Alternative has <|> and empty, with the definition that "<|> is associative" and "empty is the left and right identity for <|>" so "x <|> empty = x = empty <|> x"
2020-11-20 08:39:07 christo joins (~chris@81.96.113.213)
2020-11-20 08:40:23 <merijn> guest1120: The exact meaning of the associative operation depends on the instance. For parsers it's usually "try left, then on failure try right", and empty is "a failing parser", but for lists it's "concatenate" with empty being the empty list
2020-11-20 08:42:22 mikevdg reads about Data.Semigroup
2020-11-20 08:42:56 <merijn> Semigroups are great, we should to more of those :D
2020-11-20 08:43:41 <guest1120> dminuoso: merijn to combinate parsers, >> or <|> I should use?
2020-11-20 08:43:45 <guest1120> I'm confused now
2020-11-20 08:43:59 <tdammers> merijn: I propose adding that to the Zen Of Python, just to mess with Python cultists
2020-11-20 08:44:02 <guest1120> parse (spaces >> symbol) "lisp" input
2020-11-20 08:44:07 <merijn> guest1120: Well, that depends on what you want :)
2020-11-20 08:44:22 <guest1120> parseExpr = parseAtom <|> parseString
2020-11-20 08:44:25 <merijn> guest1120: "a >> b" is "a, then b", "a <|> b" is "a or b"
2020-11-20 08:44:38 <merijn> tdammers: :)
2020-11-20 08:44:50 <merijn> tdammers: I have more important business
2020-11-20 08:45:02 <guest1120> merijn: ok
2020-11-20 08:45:12 <tdammers> merijn: yeah, but would be fun, wouldn't it
2020-11-20 08:45:13 <merijn> tdammers: Like, figure out a good name for "Monoid m => Bool -> m -> m" so I can *finally* get it into base
2020-11-20 08:45:16 <[exa]> the kids today don't even start their first python tutorial with `import this`.
2020-11-20 08:45:41 <mikevdg> import turtle;
2020-11-20 08:45:57 <tdammers> [exa]: just yesterday I've seen someone argue that "oneThing if condition else otherThing" is great syntax
2020-11-20 08:46:02 <kritzefitz> merijn, That type doesn't seem familiar to me. What would that operator do?
2020-11-20 08:46:03 <merijn> tdammers: I'm using mif in my code now, but I'm not happy with it
2020-11-20 08:46:25 <merijn> kritzefitz: "\b x -> if b then x else mempty"
2020-11-20 08:46:31 Boomerang joins (~Boomerang@xd520f68c.cust.hiper.dk)
2020-11-20 08:46:41 <merijn> kritzefitz: It's amazing how astonishingly useful that is
2020-11-20 08:46:45 <tdammers> if anything, I'd go with mwhen rather than mif

All times are in UTC.