[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
What is a monad/bind operator/type constructor?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 9
Thread images: 1
File: Ppqic.jpg (71 KB, 960x640) Image search: [Google]
Ppqic.jpg
71 KB, 960x640
I don't program in haskell and every google search I do explains monads in terms of "Maybe Monads" and the examples are written in Haskell.

I don't fucking know Haskell and none of the examples may any sense with the maybe examples.

Can someone in laymen terms describe what
>Monads
>Bind operators
>Functors
>Type Constructors

are?

I have a math background (but not category theory), so can use some basic math to explain this shit.

My previous comment got deleted (an anon gave a good response) but... this is what I understand

>>53734130
Thanks for the thorough explanation, but none of that means anything to me. I don't know Haskell.

Can you explain what this shit means in a non-Haskell way?

I read that 'functors' are 'containers' and when you apply an operation to it, you unwrap the 'container' and apply the operation to the individual functions then 'wrap' the results back into the 'container'. So, like if you wanted to apply the binary operation of multiplication and the container type was type list and elements were int, then you'd apply multiplication to the ints and put it back into the list. Is this shit accurate? How do you formalize what a functor is (without using haskell)?

I know what monoids are... but have no idea how they or anything else applies to define the monad.

So TL;DR can you fucking tell me what a monad/bind operator/type constructor is WITHOUT using haskell?

Thanks anon
>>
>>53734446
The bind function is comparable to the fmap function of the Functor typeclass with one simple difference.

You use fmap on shit like List Int to apply a function like multiplyByTwo (signature would be Int -> Int) and get back a List Int with all numbers being multiplied by two.

So what if your function returns a List Int instead of just an Int? You'll get something like List List Int but sometimes you want just a single flat List Int.

The bind function is function composition like fmap but it turns nested shit like List List Int into List Int or Maybe Maybe Int to Maybe Int.
>>
>>53734571
Okay, so my understanding of how a functor is applied is correct?

>So what if your function returns a List Int instead of just an Int? You'll get something like List List Int but sometimes you want just a single flat List Int.


Can you explain that more?

Say you have a container-- it is a list
the elements in the list are int

You apply multiplyby2 to the ints and return a list of ints. How do you get a List List Int?
>>
>he fell for the haskel meme
>>
>>53734446

This is a strikingly easy explanation of Functors/Applicative/Monads.

http://adit (dot) io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

Monads, Functors and the bind operation have their counterparts in category theory, but they are by no means the same thing in Haskell.

Type Constructors only have a usage in Haskell (and other programming languages), and I can't think of an explanation without an example in Haskell.

>>53734571
I don't even understand this motivation. A monadic bind can do anything I want, not only join monads.

>>53734658
Your understanding of a Functor is correct.

The above linked post should explain all of your questions.

tl;dr; (the box explanation)
A Type Constructor is a box that can hold many values of possibly different types.
data Box0 = Box0 Int
data Box1 = Box1 (Int, Int)
data Box2 a = Box2 a -- a can be of any type
data Box3 a b = Box3 (a,b)


A Type Constructor which has the following functions defined is called a monad.
(>>=) :: Monad m => m a -> (a -> m b) -> m b
return :: Monad m => a -> m a


return wraps any value with the Type Constructor.
bind gets a wrapped value, a functions that gets a pure value and wraps it with the type constructor and returns this wrapped value. So what happens inside is the following.

wrappedValue >>= function = do
value <- wrappedValue -- we unwrap the value
function value -- we apply the function to the unwrapped value and get a new wrapped value which we return
>>
Wow, seems like both Haskell programmers are in this thread.
>>
>>53735127
Thanks for verifying my understanding of a function. I'm very thankful you guys are taking the time to provide such great explanations, I'm at work but will use my lunch break to start reading through this link. If for some reason thread dies I'll be the guy posting Haskell questions like these. I'm planning to just go ahead and dive into Haskell and just learn it.
>>
>>53735850
Functor* not function. Typing this from mobile.
>>
which keyboard is that? is that the razer anasi? i like the idea of more buttons for your thumb cause the spacebar is the dumbest fucking think on a keyboard. you seriously don't need that key to be so fucking huge. makes your thumb absolutely useless if you play games.
Thread replies: 9
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.