Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→ 502,152 events total
2021-03-30 11:32:31 petersen joins (~petersen@redhat/juhp)
2021-03-30 11:33:06 × stree quits (~stree@68.36.8.116) (Ping timeout: 240 seconds)
2021-03-30 11:33:14 <Jahn> Hey guys, I'm revising for an exam here and got stuck at a very basic problem.
2021-03-30 11:33:15 <Jahn> Basically, I have a function to draw an ascii triangle on size input plus the repeat function redefined (task is such):
2021-03-30 11:33:15 <Jahn> repeat :: Int-> String-> String
2021-03-30 11:33:16 <Jahn> repeat n s = if n<= 0 then "" else s ++ repeat (n-1) s
2021-03-30 11:33:16 <Jahn> triangle :: Int-> String
2021-03-30 11:33:17 <Jahn> triangle n = if n >= 1 then triangle (n-1) ++ ((repeat (n) "*") ++ "\n")
2021-03-30 11:33:17 <Jahn>                 else ""
2021-03-30 11:33:17 × Jahn quits (d98aca74@217.138.202.116) (Killed (Sigyn (Spam is off topic on freenode.)))
2021-03-30 11:33:58 shailangsa joins (~shailangs@host86-186-177-164.range86-186.btcentralplus.com)
2021-03-30 11:34:38 × gnumonic quits (~gnumonic@c-73-170-91-210.hsd1.ca.comcast.net) (Ping timeout: 268 seconds)
2021-03-30 11:35:13 <edwardk> joel135: the () and (a,b) based version was included in the original paper on Applicatives
2021-03-30 11:36:43 <joel135> hi edwardk! i see.
2021-03-30 11:38:40 <edwardk> http://www.riec.tohoku.ac.jp/~asada/papers/arrStrMnd.pdf goes into the topic of strength here, but it might be a slow slog on first reading
2021-03-30 11:38:53 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Quit: Connection closed)
2021-03-30 11:38:59 <joel135> i already started reading it, thanks
2021-03-30 11:39:09 <edwardk> k
2021-03-30 11:39:12 royal_screwup21 joins (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9)
2021-03-30 11:39:51 <joel135> I have gathered so far that any Arrow is a monad in Prof, and its strength in the sense of strong monads. Elaborately, `Arrow a` gives a profunctor `a :: *^op -> * -> *`, and this is a monoid with unit `arr :: (x -> y) -> a x y` and multiplication `(>>>) :: a x y -> a y z -> a x z`.
2021-03-30 11:41:33 JanBessai joins (~JanB@85-22-13-230.ip.dokom21.de)
2021-03-30 11:42:10 <joel135> I just need to work out that strength amounts to first' now.
2021-03-30 11:42:50 machinedgod joins (~machinedg@135-23-192-217.cpe.pppoe.ca)
2021-03-30 11:43:06 × geowiesnot quits (~user@i15-les02-ix2-87-89-181-157.sfr.lns.abo.bbox.fr) (Ping timeout: 260 seconds)
2021-03-30 11:43:34 <txb920> Apologies all for the total noob question - but why can I do "map (uncurry min) zip $ [1,2,3] [3,2,1]" (returning [1,2,3]) - but not "map (uncurry min) . zip" to compose a function accepting two arrays of integers? Just trying to get the basics straight in my head. How would I go about combining those functions? :-)
2021-03-30 11:43:44 × royal_screwup21 quits (52254809@gateway/web/cgi-irc/kiwiirc.com/ip.82.37.72.9) (Ping timeout: 246 seconds)
2021-03-30 11:44:07 <merijn> txb920: That first one looks like a type error to me
2021-03-30 11:44:16 <merijn> Unless you have a custom/different 'map' in scope
2021-03-30 11:44:18 solvr joins (57e3c46d@87.227.196.109)
2021-03-30 11:45:03 <merijn> In fact, even if you do, that first one looks *entirely* wrong to me
2021-03-30 11:45:17 × txb920 quits (5af6ddfd@90.246.221.253) (Quit: Connection closed)
2021-03-30 11:45:50 stree joins (~stree@68.36.8.116)
2021-03-30 11:46:55 <lortabac> it looks like a typo, ($) should be *before* zip
2021-03-30 11:47:13 <merijn> lortabac: Sure
2021-03-30 11:47:26 txb920 joins (5af6ddfd@90.246.221.253)
2021-03-30 11:47:50 <merijn> lortabac: But if I typo correct every beginner's question before I answer, then I end up answering the wrong question a lot :p
2021-03-30 11:48:03 <txb920> Connection died:D
2021-03-30 11:48:27 <lortabac> merijn: :)
2021-03-30 11:49:02 <merijn> txb920: https://ircbrowse.tomsmeding.com/browse/haskell?id=413034&timestamp=1617104647#t1617104647
2021-03-30 11:49:07 <Philonous> joel135, I've had good luck explaining Applicative in terms of »f a -> f b -> f (a,b)«, so I agree it's less daunting.
2021-03-30 11:50:10 <txb920> Cheers merijn. Ah, yeah. I do have the $ before zip, oops.
2021-03-30 11:50:18 <lortabac> txb920: (.) composes two functions that take 1 argument, but zip takes 2 arguments
2021-03-30 11:51:35 <merijn> txb920: Let's walk through some things
2021-03-30 11:51:53 <merijn> Let's start with "f $ x = f (x)"
2021-03-30 11:52:06 <merijn> If we introduce that in your example we get
2021-03-30 11:52:26 <merijn> map (uncurry min) (zip [1,2,3] [3,2,1])
2021-03-30 11:52:30 <merijn> THat's obviously right
2021-03-30 11:52:47 <merijn> Now consider: "f . g = \x -> f (g x)"
2021-03-30 11:52:57 <merijn> That gives us
2021-03-30 11:53:14 <merijn> \x -> map (uncurry min) (zip x)
2021-03-30 11:53:25 <merijn> :t zip []
2021-03-30 11:53:26 <lambdabot> [b] -> [(a, b)]
2021-03-30 11:53:45 <merijn> So "zip x" is a function expecting a list, mapping that makes no sense
2021-03-30 11:54:21 knupfer joins (~Thunderbi@dynamic-046-114-145-192.46.114.pool.telefonica.de)
2021-03-30 11:54:47 jakalx parts (~jakalx@base.jakalx.net) ("Error from remote client")
2021-03-30 11:55:51 jakalx joins (~jakalx@base.jakalx.net)
2021-03-30 11:56:22 DirefulSalt joins (DirefulSal@gateway/vpn/privateinternetaccess/direfulsalt)
2021-03-30 11:56:34 × knupfer quits (~Thunderbi@dynamic-046-114-145-192.46.114.pool.telefonica.de) (Client Quit)
2021-03-30 11:56:47 knupfer joins (~Thunderbi@dynamic-046-114-145-192.46.114.pool.telefonica.de)
2021-03-30 11:56:54 <txb920> Hmm, great, thanks for that merijn. That makes sense
2021-03-30 11:57:36 × knupfer quits (~Thunderbi@dynamic-046-114-145-192.46.114.pool.telefonica.de) (Remote host closed the connection)
2021-03-30 12:00:13 <merijn> txb920: Usually people ascribe too much magic to $ and . while in reality they're pretty straightforward functions :)
2021-03-30 12:02:11 <peanut_> accursedUnutterablePerformIO is magic.
2021-03-30 12:02:19 <merijn> :p
2021-03-30 12:02:43 haritz joins (~hrtz@62.3.70.206)
2021-03-30 12:02:44 × haritz quits (~hrtz@62.3.70.206) (Changing host)
2021-03-30 12:02:44 haritz joins (~hrtz@unaffiliated/haritz)
2021-03-30 12:02:48 <merijn> peanut_: "People who like 'accursedUnutterablePerformIO' also liked: GHC.Prim" ;)
2021-03-30 12:03:38 × DirefulSalt quits (DirefulSal@gateway/vpn/privateinternetaccess/direfulsalt) (Ping timeout: 260 seconds)
2021-03-30 12:03:45 <joel135> @let x = 3 in x*x
2021-03-30 12:03:45 <lambdabot> Parse failed: Parse error: in
2021-03-30 12:04:05 <joel135> how to use lambdabot ?
2021-03-30 12:04:11 <merijn> > let x = 3 in x*x
2021-03-30 12:04:12 <lambdabot> 9
2021-03-30 12:04:19 <joel135> >let x = 3
2021-03-30 12:04:23 <joel135> > x*x
2021-03-30 12:04:25 <lambdabot> x * x
2021-03-30 12:04:29 <merijn> That doesn't work
2021-03-30 12:04:43 <merijn> > only accepts expressions
2021-03-30 12:04:52 <merijn> let without in is part of do notation
2021-03-30 12:05:17 × jbetz quits (sid283648@gateway/web/irccloud.com/x-bfgqfnucldondvhy) (Quit: Connection closed for inactivity)
2021-03-30 12:05:35 <merijn> > do { let x = 3; x*x; } -- I guess this should work
2021-03-30 12:05:36 <lambdabot> <hint>:1:20: error: <hint>:1:20: error: parse error on input ‘;’
2021-03-30 12:05:40 geekosaur joins (82650c7a@130.101.12.122)
2021-03-30 12:05:46 <merijn> > do { let x = 3; x*x } -- I guess this should work
2021-03-30 12:05:48 <lambdabot> <hint>:1:21: error: <hint>:1:21: error: parse error on input ‘}’
2021-03-30 12:05:58 <merijn> oh, wait
2021-03-30 12:06:08 <geekosaur> let { x = 3 };
2021-03-30 12:06:09 <merijn> > do { let { x = 3 }; x*x }
2021-03-30 12:06:11 <lambdabot> 9
2021-03-30 12:07:35 <peanut_> merijn, I use GHC.Prim all the time :^)
2021-03-30 12:07:47 <peanut_> indirectly ;)
2021-03-30 12:08:04 <joel135> :t let (.:) = (.).(.) in map (uncurry min) .: zip
2021-03-30 12:08:05 <lambdabot> Ord b => [b] -> [b] -> [b]
2021-03-30 12:08:19 <merijn> peanut_: So does everyone writing Haskell :p
2021-03-30 12:08:27 knupfer joins (~Thunderbi@dynamic-046-114-145-192.46.114.pool.telefonica.de)
2021-03-30 12:08:35 <peanut_> exactly
2021-03-30 12:09:11 enoq joins (~textual@194-208-146-143.lampert.tv)
2021-03-30 12:11:36 <joel135> Ok I worked it out. Strength is in general of the form `(F u) ⊗ v → F(u ⊗ v)` and in this case this means -- if you squint at it -- `(a x y, r -> s, (y, s) -> t) -> exists w. ((x, r) -> w, a w t)` which should boil down to first'. Indeed, it can be simplified to `a x y -> a (x, r) (y, r)` by 3 appeals to Yoneda that eliminate the variables s, t and w.
2021-03-30 12:12:01 × Franciman quits (~francesco@host-79-53-62-46.retail.telecomitalia.it) (Quit: Leaving)

All times are in UTC.