Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell is

Name: Anonymous 2008-06-17 17:37

the white man's burden of programming languages.

Name: Anonymous 2008-06-20 18:03

Okay, tell me if I'm right.
>>= takes a monad and a function, executes the monad with the function and packs the result into another monad.
Right?

Name: Anonymous 2008-06-20 18:29

>>41
No, >>= returns the monad that results of applying the argument function to the argument monad's value (you can tell by >>='s type: Monad m => m a -> (a -> m b) -> m b). The argument monad will only be actually executed when the result monad is executed.

Name: Anonymous 2008-06-20 18:36

So, I was partially right, except it just applies the function to the monad and doesn't execute it, hm?

Name: Anonymous 2008-06-20 18:42

>>43
Not quite, it applies the function to the monad's value, not the monad itself. If the function received a monad as argument, it could be applied directly to a monad, like in runIdentity (return 42).

Name: Anonymous 2008-06-20 18:44

Name: Anonymous 2008-06-20 18:54

Okay, thanks, I pretty much have the general idea now.

Name: Anonymous 2008-06-20 18:57

>>46
Why, you're most welcome. Also, have you read your YAHT today?

Name: Anonymous 2008-06-20 19:01

>>46
The best tutorial about monads, IMO:
http://www.haskell.org/all_about_monads/html/index.html

Name: Anonymous 2008-06-20 19:02

>>47
I have read it some time ago. Now I'm trying again with ``A Gentle Introduction to Haskell''.

Name: Anonymous 2008-06-20 19:22

baskell cs ull ubout gonads.

Name: Anonymous 2008-06-20 19:27

I only skimmed the tutorial. After reading blog post after blog post about Haskell (from reddit), I suddenly found I was fluent in the language at the start of last summer.
It is a great honor to be numbered among those /prog/ elites, the Haskellites.

Name: Anonymous 2008-06-20 19:37

>>51
more like haskFAILS, lol!

Name: Anonymous 2008-06-20 23:37

A monad is like carrying the world on your shoulders!

Name: Anonymous 2008-06-21 0:18

>>51,53
Kid, you look like you're ready to take on the world!

Name: Anonymous 2008-06-21 6:57

I am reading the monad tutorial right now.

Name: Anonymous 2008-06-21 7:05

I took a peek at the first two examples and I understand everything without even reading anything. I feel mighty fine.

Name: Anonymous 2008-06-21 8:00

>>56
Now do Arrows.

Name: Anonymous 2008-06-21 8:45

hax my ಊ

Name: Anonymous 2008-06-21 9:32

>>56
Are you talking about "All About Monads" or the monad chapter of YAHT?

Name: Anonymous 2008-06-21 9:35

>>59
The ``All About Monads''.

Name: Anonymous 2008-06-21 9:54

>>59
Funny, the same thing happened to me with the monad chapter of YAHT, but it took more than two examples.

Name: Anonymous 2008-06-21 9:55

>>60
Funny, the same thing happened to me with the monad chapter of YAHT, but it took more than two examples.

Name: Anonymous 2008-06-21 10:13

assemblyLine w = (return w) >>= makeChopsticks >>= polishChopsticks >>= wrapChopsticks
assemblyLine w = (return w)
It carries out and is w

Name: Anonymous 2008-06-21 17:04

So once again:

Monads are like normal computations, except they carry some special info that allows them to act in some special situations that normally couldn't be handled (like the Maybe monad being able to handle lack of arguments by Nothing).

Tell me how close am I.

Name: Anonymous 2008-06-21 17:16

hax my anus

Name: Anonymous 2008-06-21 17:56

>>64
Very close to haxing my anus.

Name: Anonymous 2008-06-21 18:15

Name: Anonymous 2008-06-21 18:42

Fuck this shit, I'm learning Python.

Name: Anonymous 2008-06-21 18:47

>>64
The Monad class is a way of generalising. All instances of the Monad class must implement >>= and return, and the way they are implemented must satisfy the following rules (1) return a >>= f = f a (left identity), (2) m >>= return = m (right identity), (3) (m >>= f) >>= g = m >>= (\x -> f x >>= g) (associativity). These allow you to reason more straight-forwardly about monadic code. (>>=) :: forall a b . m a -> (a -> m b) -> m b and return :: a -> m a. Other than that, what your Monad instances do is irrelevant. They can hold state (State, Reader), or no state ([a] (list monad), Maybe), produce side effects (IO, STM), provide continuation facilities (Cont), and so forth. The implementations of particular monads are not relevant to what the concept of Monads is, which is abstracting a pattern of computation and generalising it, thanks to type classes. There is nothing more to it.

Name: Anonymous 2008-06-21 18:48

>>68
I lol'd.

Name: Anonymous 2008-06-21 18:53

Name: Anonymous 2008-06-21 18:55

>>70
You might have lol'd, but  my rage at my inability to grasp simple concepts is inexpressible with words.

Name: Anonymous 2008-06-21 18:55

instance  Monad Maybe  where
    (Just x) >>= k      = k x
    Nothing  >>= _      = Nothing

    (Just _) >>  k      = k
    Nothing  >>  _      = Nothing

    return              = Just
    fail _        = Nothing

Name: !!aBJKZuplTV/HGe3 2008-06-21 19:06

>>31
Try implementing the State monad or Parsec in Javascript, like I did. http://chrisdone.com/stuff Then realise they are not monads because Javascript doesn't have polymorphism so one can't generalise the bindM and returnM functions. That's what monads are all about.

Name: Anonymous 2008-06-21 19:07

>>74
(Or, indeed, implement them in Python or whatever language you use that has closures.)

Name: Anonymous 2008-06-21 19:37

>>73
I get that part. I was able to come up with it myself. I get the technical part and how do the monads work, but I have no idea what actually is a monad and why would I want to use them.

Name: Anonymous 2008-06-21 19:43

>>76
They are capsules. You put something into a capsule with return and you pull the contents out of a capsule with bind.

Name: Anonymous 2008-06-21 19:44

>>76
A Monad is an instance of the Monad class. You want to use them because you can use all instances of Monad ("monads") in the same general way (think do { ...; ... <- ...; ...}, mplus). That is all.

Name: Anonymous 2008-06-21 19:46

OK GUYS, STOP. STOP IT. STOP TALKING ABOUT MONADS. STOP TALKING ABOUT NOMADS. STOP TALKING ABOUT FUCKING SHIT NOBODY REALLY UNDERSTANDS. JUST FUCKING STOP. STOP THIS THREAD

Name: Anonymous 2008-06-21 19:50

>>76,78
IO monad:
main = do
  mapM_ putStrLn ["hey","guise"]


STM monad:
withdraw :: Account -> Int -> STM ()
withdraw acc amount
  = do { bal <- readTVar acc
       ; writeTVar acc (bal - amount) }


Parser (Parsec) monad:
parens  :: Parser ()
parens  = do{ char '('
            ; parens
            ; char ')'
            ; parens
            }
        <|> return ()


Do you see a pattern forming here? Thank god we abstracted that shit, yo!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List