Secret Haskell Composition Technique

Ғылым және технология

MONADS DO NOT COMPOSE
Support: / tsoding

Пікірлер: 75

  • @arturjorge5607
    @arturjorge56074 жыл бұрын

    "You still perform double penetration, but you hide it from the user" - - Tsoding

  • @RexNg1123
    @RexNg11234 жыл бұрын

    Tsoding trolling us by asking us to implement the composition of monads 🤣

  • @kriswright5112
    @kriswright51124 жыл бұрын

    the bottom of the screen says "Porn Folder: 43.9 GiB"...that's not nearly enough, man.

  • @quaternaryyy

    @quaternaryyy

    4 жыл бұрын

    too smol PepeHands

  • @LucianoRobino

    @LucianoRobino

    4 жыл бұрын

    Well there are a lot of penetrations and double penetrations in the video

  • @GotoFail
    @GotoFail4 жыл бұрын

    Tsoding is the king of penetration

  • @nilp0inter2

    @nilp0inter2

    3 жыл бұрын

    And double penetrantion as well

  • @EidosGaming

    @EidosGaming

    3 жыл бұрын

    @@nilp0inter2 fmap . fmap so?

  • @StefanReich
    @StefanReich4 жыл бұрын

    I love how you use the word "secret" to make this video more appealing to click on

  • @objectobject6172

    @objectobject6172

    3 жыл бұрын

    Sure appealed to me

  • @SimGunther
    @SimGunther4 жыл бұрын

    "Injecting" things is how we get endofunctors. Truly the mathematical way of doing compositions and metaprogramming.

  • @thinkbait8363

    @thinkbait8363

    4 жыл бұрын

    pun intended?

  • @stintaa
    @stintaa24 күн бұрын

    Rewatching your old videos, and this intro hit as hard as it did 4 years ago :D

  • @brettm4179
    @brettm41794 жыл бұрын

    Rust values can be mapped. It's pretty easy to implement a functor trait. Unwrap is actually a code smell

  • @weirdblackcat

    @weirdblackcat

    4 жыл бұрын

    You can't do it generically though because Rust doesn't support higher-kinded types, which means no fmap. There's a big GH issue to bring HKTs to Rust one day so the Rust community can start writing monad tutorials like "A monad is just a shell exchanging crabs bro what's the problem???"

  • @YuriAlbuquerque

    @YuriAlbuquerque

    3 жыл бұрын

    it's impossible to implement a functor trait in Rust, as of now.

  • @DanDart
    @DanDart4 жыл бұрын

    Ah hell yea so that's how you use it! How about triple without fmap? Maybe one on transformers / free monads or effects to help "compose" monads?

  • @NikolajLepka
    @NikolajLepka4 жыл бұрын

    "In Rust you unwrap everything" Oh yeah? fmap (\x -> x + 1) (Just 5) is written Some(5).map(|x| x + 1); in Rust no unwrap required.

  • @jethrolarson

    @jethrolarson

    3 жыл бұрын

    I dont think he was saying you can't but that devs often don't. I've seen this in other languages like java

  • @NikolajLepka

    @NikolajLepka

    3 жыл бұрын

    @Sydney Bean the question mark operator is just monadic bind in the context of optionals. It performs the exact same function

  • @NikolajLepka

    @NikolajLepka

    3 жыл бұрын

    @Sydney Bean Point is: fn test1() -> Option { let a = may_fail()?; let b = may_also_fail()?; Some(a + b) } is the same as fn test2() -> Option { may_fail().and_then(|a| may_also_fail().map(|b| a + b)) } play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d5e6fa175cdba9bc18b108c98f828124

  • @chaoky

    @chaoky

    3 жыл бұрын

    @@NikolajLepka how would this look like in Haskell?

  • @NikolajLepka

    @NikolajLepka

    3 жыл бұрын

    @@chaoky the link I posted in the comment has the Haskell versions written in comments

  • @ariashark
    @ariashark4 жыл бұрын

    text version of would be called "apply". if you're talking about the specific operator I call it the spaceship operator

  • @variadicism1047

    @variadicism1047

    4 жыл бұрын

    That might be confused with the spaceship operator in languages like Perl, .

  • @chromosundrift

    @chromosundrift

    2 жыл бұрын

    @@variadicism1047 not likely!

  • @davidyanceyjr
    @davidyanceyjr4 жыл бұрын

    Thanks for another great video, maybe a tut about haskell memoization for us mere mortals. This mortal is struggling.

  • @alurma
    @alurma4 жыл бұрын

    nice. glad i subscribed half a year ago

  • @user-ss7eh7xf1b
    @user-ss7eh7xf1b4 жыл бұрын

    Yay! Haskell it is!

  • @TheHHG7
    @TheHHG74 жыл бұрын

    I know you are partiality joking about Rust developers unwraping everything, but there do exist functor and monadic functions in rust for Option, Result, and other types and should be used along with the try operator when you need use wrapped values (much like do notation).

  • @johannbauer2863
    @johannbauer28634 жыл бұрын

    You can (and should) use map on Option in Rust

  • @maximkovalkov1334
    @maximkovalkov13344 жыл бұрын

    inb4 this gets demonetized for "double penetration"

  • @web3tel
    @web3tel4 жыл бұрын

    why not newtype Compose , bljat'?!

  • @valcron-1000
    @valcron-10004 жыл бұрын

    That intro tho...

  • @nerkulec
    @nerkulec3 жыл бұрын

    yay i wanna be on the list of people at the end

  • @AryadevChavali
    @AryadevChavali4 жыл бұрын

    2:31 "b-but alexey w-we haven't even been on a date yet..."

  • @Nathankthanks
    @Nathankthanks3 жыл бұрын

    I'm following allowing in VS Code, and I'm curious why the linter included with the haskell extension is recommending `newtype` instead of `data`. Do you have an opinion Tsoding?

  • @aaoth4689

    @aaoth4689

    2 жыл бұрын

    in this case newtype is better because it essentially creates a wrapper for your types which exists only in design time and is stripped in runtime. so by using newtype you aren't creating new entities, just referencing the same types and implementing different interfaces for them

  • @agivney
    @agivney4 жыл бұрын

    Another great tutorial. The only thing; my brain hurts.

  • @user-xm9xo7jg4u
    @user-xm9xo7jg4u2 жыл бұрын

    What the text editor are you using? It looks so cool.

  • @Egzvorg

    @Egzvorg

    Жыл бұрын

    That's emacs

  • @lclutz
    @lclutz4 жыл бұрын

    amazing intro 😂

  • @SomeMrMindism
    @SomeMrMindism4 жыл бұрын

    This is a very nice and elegant solution. However it's a little bit unsatisfactory that it only wraps two functors at a time... is there a way to declare a recursive datatype that fmaps over an arbitray length of composition? A little bit like the free monad

  • @JaycenGiga

    @JaycenGiga

    4 жыл бұрын

    You could nest the compose. Then the outer compose uses the fmap of the inner one in its fmap, so everything would work automatically.

  • @kriswright5112

    @kriswright5112

    4 жыл бұрын

    ((+1) ) (map Just [0..4]) gives [Just 1,Just 2,Just 3,Just 4,Just 5]

  • @SomeMrMindism

    @SomeMrMindism

    4 жыл бұрын

    @@JaycenGiga Yes, but then to get the inner value you'd need to know how long the chain is.

  • @SomeMrMindism

    @SomeMrMindism

    4 жыл бұрын

    @@kriswright5112 I'm sorry but I don't understand what you're trying to say. You've just switched the two functors

  • @kriswright5112

    @kriswright5112

    4 жыл бұрын

    @@SomeMrMindism i don't know what I'm trying to say either. the only recursive datatype I know in Haskell is Tree. Maybe you could do something like the Functor Tree example from learnyouahaskell but instead of left and right branches, just do a right branch. don't know. I'm just learning Haskell.

  • @daviddawkins
    @daviddawkins3 жыл бұрын

    That was great, thank you! Now, I thought `bind` was *exactly* a composition of monads? The comments here suggest otherwise.

  • @DanDart
    @DanDart4 жыл бұрын

    2:26 succ

  • @JaimePascual
    @JaimePascual4 жыл бұрын

    ...Next train to "JSON Parser" station departs in 26 minutes 44 seconds from "Tsoding Channel" platform...

  • @bernardostearns9696
    @bernardostearns96964 жыл бұрын

    this guy is the best

  • @thinkbait8363
    @thinkbait83634 жыл бұрын

    If this channel needs one thing, it's regular scheduling

  • @user-qt4gz1dl6w

    @user-qt4gz1dl6w

    Жыл бұрын

    See tsoding daily

  • @user-qt4gz1dl6w

    @user-qt4gz1dl6w

    Жыл бұрын

    I know that you wrote it 3 years before

  • @quintencabo
    @quintencabo5 ай бұрын

    20:13 g that contains b, that just made so much things click!

  • @skepticmoderate5790
    @skepticmoderate57903 жыл бұрын

    "Rust developers must constantly unwrap everything." Uh... we have Option::map and Either::map_ok. Sure, they're not typeclasses, but they're still quite composable.

  • @kohlensaurerulpser2595
    @kohlensaurerulpser25954 жыл бұрын

    I thought monads do not compose in general.. edit ok just saw the description of the vid lol

  • @user-yj4xq6ix5n
    @user-yj4xq6ix5n10 ай бұрын

    it bothers me soo much that the type signature of is () :: Functor f => (a -> b) -> f a -> f b and not () :: Functor f => f a -> (a -> b) -> f b with the second signature we could've written beautiful code like foo :: Functor a -> Functor b foo x = x func1 func2 func 3 just like the monad >>= operator

  • @drdilyor

    @drdilyor

    9 ай бұрын

    you can use for exactly that. is defined that way to be similar to $. is also similar to &. is defined in Data.Functor, & is defined in Data.Function

  • @gdargdar91
    @gdargdar913 жыл бұрын

    Monads don't compose lol

  • 2 жыл бұрын

    damn - I really want to share this with my co-workers but it's clearly NSFW

  • @user-ck1kx5ie6t
    @user-ck1kx5ie6t4 жыл бұрын

    fmap = fmap . fmap pure = pure . pure 😜

  • @Bratjuuc

    @Bratjuuc

    2 жыл бұрын

    liftA2 = liftA2 . liftA2

  • @Bratjuuc
    @Bratjuuc2 жыл бұрын

    defining liftA2 instead of () for Compose is much easier and intuitive instance (Applicative f, Applicative g) => Applicative (Compose f g) where pure = Compose . pure . pure liftA2 f (Compose a) (Compose b) = Compose $ (liftA2 . liftA2) f a b

Келесі