Logs: freenode/#haskell
| 2021-04-25 16:40:51 | <HelplessProgramm> | hmm |
| 2021-04-25 16:41:01 | <hpc> | > (+) <$> [1, 2, 3] <*> [10, 100, 1000] |
| 2021-04-25 16:41:03 | <lambdabot> | [11,101,1001,12,102,1002,13,103,1003] |
| 2021-04-25 16:41:31 | <HelplessProgramm> | So i could put that and thats it? |
| 2021-04-25 16:41:34 | <HelplessProgramm> | With my function |
| 2021-04-25 16:41:40 | <hpc> | yes |
| 2021-04-25 16:41:43 | <HelplessProgramm> | Rocks |
| 2021-04-25 16:41:46 | <hpc> | but still learn Applicative, it's crazy good |
| 2021-04-25 16:42:13 | <HelplessProgramm> | I try but it's still way over my head |
| 2021-04-25 16:42:58 | <hpc> | have you looked at Functor? i notice you said map instead of fmap |
| 2021-04-25 16:43:07 | <HelplessProgramm> | Yeaah |
| 2021-04-25 16:43:09 | × | nineonine quits (~nineonine@2604:3d08:7785:9600:bde3:c459:7b57:e4c8) (Ping timeout: 250 seconds) |
| 2021-04-25 16:43:18 | <HelplessProgramm> | Ive looked into functor applicative and monad |
| 2021-04-25 16:43:25 | <HelplessProgramm> | It's really hard |
| 2021-04-25 16:43:57 | × | mikoto-chan quits (~anass@gateway/tor-sasl/mikoto-chan) (Ping timeout: 240 seconds) |
| 2021-04-25 16:44:26 | <monochrom> | Have you written your own recursion for this? |
| 2021-04-25 16:44:34 | × | gehmehgeh quits (~ircuser1@gateway/tor-sasl/gehmehgeh) (Quit: Leaving) |
| 2021-04-25 16:44:42 | <monochrom> | Do you want guidance for writing your own recursion for this? |
| 2021-04-25 16:44:58 | <HelplessProgramm> | Yeah i still struggle with it |
| 2021-04-25 16:45:30 | <gnumonic> | it's not really that bad. functors are boxes you can map functions over. fmap (+1) [1,2,3] = [2,3,4]. applicatives are containers that you can put functions into, and apply those containers full of functions to containers full of values to get back a container of the result values (more or less) |
| 2021-04-25 16:45:31 | <monochrom> | OK first you should write your own version of map for practice. |
| 2021-04-25 16:46:09 | <HelplessProgramm> | container, thats the hard keyword |
| 2021-04-25 16:46:13 | <HelplessProgramm> | ro understand i think |
| 2021-04-25 16:46:41 | <monochrom> | After that, this may or may not be obvious: note that you want f [a,b] [x,y] = [foo a x, foo a y, foo b x, foo b y] for example. |
| 2021-04-25 16:46:57 | <monochrom> | Actually let me make it longer. |
| 2021-04-25 16:47:11 | <gnumonic> | i don't think it'd be helpful to elaborate on what "container" *really* means there :P it'd probably scare you |
| 2021-04-25 16:47:27 | <monochrom> | You want foo [a,b,c] [x,y] = [foo a x, foo a y, foo b x, foo b y, foo c x, foo c y] |
| 2021-04-25 16:47:35 | <HelplessProgramm> | small doubt, what if the function is actually foo :: int -> int -> Maybe Int |
| 2021-04-25 16:47:48 | <HelplessProgramm> | Does that snippet still work? the one with applicative |
| 2021-04-25 16:48:11 | <HelplessProgramm> | > (+) <$> [1, 2, 3] <*> [10, 100, 1000] this one, if the function returns a maybe |
| 2021-04-25 16:48:11 | <monochrom> | = [foo a x, foo a y] : the rest = map (foo a) [x,y] : the reset |
| 2021-04-25 16:48:13 | <lambdabot> | <hint>:1:47: error: <hint>:1:47: error: parse error on input ‘,’ |
| 2021-04-25 16:48:23 | <hpc> | it'll produce [Maybe Int] |
| 2021-04-25 16:48:41 | <HelplessProgramm> | Is that bad? |
| 2021-04-25 16:48:47 | <hpc> | depends on what you want |
| 2021-04-25 16:48:57 | <monochrom> | So this suggests using recursion and map again, map (foo a) [x,y] : recursion |
| 2021-04-25 16:49:03 | <HelplessProgramm> | well i don't want to find Nothing in some positions |
| 2021-04-25 16:50:02 | <hpc> | you can use another function to remove the Nothings |
| 2021-04-25 16:50:15 | <monochrom> | Frankly and bluntly I oppose going to Applicative or even Functor at this stage. |
| 2021-04-25 16:50:38 | <HelplessProgramm> | hmmm |
| 2021-04-25 16:51:10 | <monochrom> | this early stage |
| 2021-04-25 16:51:12 | × | petersen quits (~petersen@redhat/juhp) (Ping timeout: 240 seconds) |
| 2021-04-25 16:51:13 | <HelplessProgramm> | so if i put map (foo a)[x, y] that works? |
| 2021-04-25 16:51:19 | × | shad0w_ quits (a0ca2598@160.202.37.152) (Quit: Connection closed) |
| 2021-04-25 16:51:25 | <HelplessProgramm> | x,,y being my lists i guess |
| 2021-04-25 16:51:48 | <HelplessProgramm> | what function it is to remove the nothings? |
| 2021-04-25 16:51:53 | <gnumonic> | lists are kind of confusing because thinking of a list as a non-deterministic computation (which you sorta have to do to grok the applicative instance) is weird if you're looking at them as "basically imperative arrays", which is probably how this person is looking at them |
| 2021-04-25 16:51:53 | <monochrom> | err, map (foo a) [x, y] ++ recursion |
| 2021-04-25 16:52:27 | → | cfricke joins (~cfricke@unaffiliated/cfricke) |
| 2021-04-25 16:52:41 | → | heatsink joins (~heatsink@108-201-191-115.lightspeed.sntcca.sbcglobal.net) |
| 2021-04-25 16:52:51 | <gnumonic> | :t (Identity 2) |
| 2021-04-25 16:52:52 | <lambdabot> | Num a => Identity a |
| 2021-04-25 16:53:34 | <gnumonic> | Identity is a functor. If you have a function over "a", you can use fmap to apply it to the "a" inside of an "Identity" |
| 2021-04-25 16:53:41 | <gnumonic> | fmap (+1) (Identity 2) |
| 2021-04-25 16:54:00 | <HelplessProgramm> | hmm |
| 2021-04-25 16:54:14 | <gnumonic> | er that should spit out Identity 3 (i never use lambdabot) |
| 2021-04-25 16:54:26 | <HelplessProgramm> | :t (Identity 3) |
| 2021-04-25 16:54:28 | <lambdabot> | Num a => Identity a |
| 2021-04-25 16:54:28 | <monochrom> | https://chrisdone.com/posts/teaching/ |
| 2021-04-25 16:55:27 | → | nineonine joins (~nineonine@2604:3d08:7785:9600:bde3:c459:7b57:e4c8) |
| 2021-04-25 16:55:45 | <gnumonic> | but say you have a function in a container. Like: |
| 2021-04-25 16:55:53 | <gnumonic> | :t (Identity (+1)) |
| 2021-04-25 16:55:54 | <lambdabot> | Num a => Identity (a -> a) |
| 2021-04-25 16:56:03 | → | Guest6509 joins (~laudiacay@67.176.215.84) |
| 2021-04-25 16:56:44 | × | nineonine quits (~nineonine@2604:3d08:7785:9600:bde3:c459:7b57:e4c8) (Remote host closed the connection) |
| 2021-04-25 16:57:34 | <gnumonic> | you can't fmap that function that's inside the container over another container. if you try fmap (Identity (+1)) (Identity 3) it won't give you Identity 4 |
| 2021-04-25 16:57:34 | → | nineonine joins (~nineonine@2604:3d08:7785:9600:bde3:c459:7b57:e4c8) |
| 2021-04-25 16:57:35 | <HelplessProgramm> | this assignment is so hard |
| 2021-04-25 16:58:05 | <monochrom> | That won't get people to give solutions to you, by the way. |
| 2021-04-25 16:58:25 | <HelplessProgramm> | lmao |
| 2021-04-25 16:58:28 | <HelplessProgramm> | Well |
| 2021-04-25 16:58:29 | <gnumonic> | but identity is also an applicative. and the <*> operator lets you smash together Identity (+1) and Identity 3 |
| 2021-04-25 16:58:31 | <HelplessProgramm> | I have this statement |
| 2021-04-25 16:58:34 | <gnumonic> | :t (<*>) |
| 2021-04-25 16:58:36 | <lambdabot> | Applicative f => f (a -> b) -> f a -> f b |
| 2021-04-25 16:58:42 | <HelplessProgramm> | That one! |
| 2021-04-25 16:58:43 | <monochrom> | But I'm sure you're making it harder than necessary by heeding advice on caring about Functor and Applicative. |
| 2021-04-25 16:58:55 | <monochrom> | Pretty sure this is just a recursion assignment. |
| 2021-04-25 16:59:23 | <gnumonic> | so, Identity (+1) <*> Identity 3 |
| 2021-04-25 16:59:28 | <gnumonic> | gives you Identity 4 |
| 2021-04-25 16:59:42 | <monochrom> | #haskell people are famous for not caring what your current level is, and just force-feed you whatever they themselves care. |
| 2021-04-25 17:00:02 | <HelplessProgramm> | It's the hardest language i've seen by far |
| 2021-04-25 17:00:11 | <HelplessProgramm> | Too abstract |
| 2021-04-25 17:00:11 | × | Guest6509 quits (~laudiacay@67.176.215.84) (Ping timeout: 240 seconds) |
| 2021-04-25 17:00:35 | <monochrom> | If you ask so much as "how do I apply f to x" they'll answer "check out Kan extensions". |
| 2021-04-25 17:00:55 | <HelplessProgramm> | lol |
| 2021-04-25 17:01:01 | <HelplessProgramm> | I can't use libraries |
| 2021-04-25 17:01:05 | <HelplessProgramm> | For this |
| 2021-04-25 17:01:18 | × | coot quits (~coot@37.30.50.130.nat.umts.dynamic.t-mobile.pl) (Quit: coot) |
| 2021-04-25 17:01:32 | <gnumonic> | i was just trying to explain the above example to him. i don't really think it's that hard. i mean understanding how to use all this stuff together is hard but the basics of "put function in container, smash container with function in it into container w/ value in it" |
| 2021-04-25 17:01:36 | <gnumonic> | isn't really rocket science |
| 2021-04-25 17:02:13 | × | nineonine quits (~nineonine@2604:3d08:7785:9600:bde3:c459:7b57:e4c8) (Ping timeout: 250 seconds) |
| 2021-04-25 17:02:37 | <hpc> | to be fair, that question was the classic first use of Applicative |
| 2021-04-25 17:02:57 | <HelplessProgramm> | Yeah I think i had to use that |
| 2021-04-25 17:03:05 | <HelplessProgramm> | But it's still very hard for me |
| 2021-04-25 17:03:19 | <monochrom> | <*> counts as library function. |
| 2021-04-25 17:03:49 | <HelplessProgramm> | How do i remove Nothings from a list? |
| 2021-04-25 17:04:18 | <HelplessProgramm> | {-# LANGUAGE RecordWildCards #-} |
| 2021-04-25 17:04:18 | <HelplessProgramm> | import Data.Char (isUpper) |
| 2021-04-25 17:04:19 | <HelplessProgramm> | import Data.List (nub, isInfixOf) |
All times are in UTC.