main is defined to be the entry point of a Haskell program (similar to the main function in C), and must have an IO type, usually IO (). and must have an IO type
Huh?
i am a JAVA. i ahev a long doc and i make programs w/ my API. if you dont repost this comment on 10 other pages i will hax your anus tonight and make a mess of your computer and ass
Oh, I remember now: you can end main in sequence [...] instead of sequence_ [...]. It saves you from having to type the extra "_" (I'm sure there are better examples of usefulness).
Name:
Anonymous2008-06-17 20:07
>>25 sequence_ IS FASTER THAN sequence SINCE IT CAN IGNORE THE RETURN VALUES YOU DUMB SHIT. GOD PEOPLE LIKE YOU MAKE SPJ CRY AT NIGHT.
Name:
Anonymous2008-06-17 20:13
hyryst?
\
ಊ
Name:
Anonymous2008-06-17 20:14
>>22
When the whole program fails and returns a non-0 value.
Haskell's burden is to serve as an example of clean side effect programming, much like how Europe's burden is to show the Americans how to live their lives.
Name:
Anonymous2008-06-20 16:04
Every time I want to get into Haskell, I just can't get past the chapter about monads. I've tried three tutorials already and I'm nowhere as close to understanding monads.
>>31
A Monad is like a piece of code waiting to be executed. getLine, for example, returns a value of type IO String, which is a piece of code that when executed will produce a string. You can only get the value out of a monad when you execute that monad. For most monads you do that by passing them as arguments to a monad executing function (like runIdentity for Identity monad). In the case of the IO monad, however, you can only execute them by embedding them (directly or indirectly) into the monad returned by main. Hope this helps.
Name:
Anonymous2008-06-20 16:39
SO do you create a monad that, when executed, returns a number, with return 42
?
Also, is sequence an executing function like runIdentity
?
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:
Anonymous2008-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:
Anonymous2008-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:
Anonymous2008-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).
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.
assemblyLine w = (return w) >>= makeChopsticks >>= polishChopsticks >>= wrapChopsticks assemblyLine w = (return w)
It carries out and is w
Name:
Anonymous2008-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).
>>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.
>>70
You might have lol'd, but my rage at my inability to grasp simple concepts is inexpressible with words.
Name:
Anonymous2008-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/HGe32008-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:
Anonymous2008-06-21 19:07
>>74
(Or, indeed, implement them in Python or whatever language you use that has closures.)
Name:
Anonymous2008-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:
Anonymous2008-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:
Anonymous2008-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:
Anonymous2008-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
>>74
A monad is a monad whatever you call the bind etc functions.
>>76
Either because your language has to pay for being lazy or because you want to abstract control flow and state (Maybe is C's && on steroids, List is map on steroids etc).
putStr $ cycle "MONADS EVERY-FUCKING-WHERE!!! FUCKING GET ME OUT OF HERE!!! SHITFUCKCUNTFAGGOTBITCHAAAAAARGH "
Name:
Anonymous2008-06-22 0:16
>>84 Try implementing the State monad or Parsec in Javascript ... 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. A monad is a monad whatever you call the bind etc functions.
You seem to be confused.
Name:
Anonymous2008-06-22 0:57
Javascript doesn't have polymorphism
You obviously don't know Javascript.
Name:
Anonymous2008-06-22 4:31
Thank you, /prog/, I didn't know that you could be so helpful ;_;
Name:
Anonymous2008-06-22 8:08
>>86
Whether you overload one name or give them all another name is irrelevant, certainly not ``what monads are all about''.
Don't forget about the JavaScript Haskell interpreter.
Name:
Anonymous2008-06-22 10:14
I'm going to read my Closing Time now. Then, after ten hours, I will try approaching the monads again. It worked with some hard moments in the SICP.
Name:
Anonymous2008-06-22 12:02
>>89,84
The names don't have anything to do with it. The point is it's hard to have polymorphic (e.g. overloaded) functions in JavaScript, and using objects to do it (overriding) is messy and ugly imo (I've tried it--but if you've had success, I'd like to see). And this is just an example to demonstrate that monads aren't monads without type classes or generic functions or some other polymorphic function facility to generalise the computation.
I might as well end this discussion here because I am arguing from repetition.
>>96
Not lazy evaluation, nor have superior type and data polymorphism.
Name:
Anonymous2008-06-22 19:31
For haskell to do what JS can do it takes 100kloc+ of haskell to pull off and by the time you do lazy eval fills your memory up with so much shit that your computer or the process crashes.
Name:
Anonymous2008-06-22 19:35
>>98
OH NO HE DIDN'T! Are you gonna let >>99 get away with saying shit like that?
Name:
Anonymous2008-06-22 19:47
>>99
Good thing those lines are all in the compiler.
Name:
84,862008-06-22 20:44
>>Christopher
Which kind of polymorphism do you mean? I thought you meant it in the way that >>= can refer to different functions depending on which monad is inferred. This is what I attacked in my previous posts, whether the bind for List and Maybe are both called >>= or list>>= and maybe>>= is irrelevant. If you mean parametric polymorphism, Jabbascript has no problem with it because it does not have a fascist type system: > function id(x) { return x; } id(1)
1 id("lol")
"lol"
Name:
Anonymous2008-06-22 20:52
>>102
Haskell has an id function. Enjoy your lonely life as a troll.
Name:
Anonymous2008-06-22 20:59
>>102
I think he means that Javascript would allow something like aList.bind(putStr("Christopher")), so you would have to do typecheck the argument of bind by hand to make sure you're not binding monads of different kinds. Or maybe he doesn't mean that, the fuck do I know?
>>103
Nobody was talking about Haskell's id function. Stop trolling yourself.
>>104,106
Javascript doesn't do that kind of typechecking. I don't see the problem, nor how that relates to monads and polymorphism.
Name:
Anonymous2008-06-22 22:12
>>107
I'm not sure I understand either, but seems to me that the problem would be the mixing of monads, like binding a function that returns a State monad to an IO monad, or something. But then you'd just get a runtime error instead of a compilation error. Yeah, I don't know.
Name:
Anonymous2008-06-22 22:20
I heard in javascript that lists are heterogeneous.
I heard in javascript there was this MAGIC called eval
I heard in javascript ....
repeat
Name:
Anonymous2008-06-22 22:22
js isn't useful without a DOM to traverse.
Name:
Anonymous2008-06-22 22:24
>>110
Haskell isn't useful without an AST to traverse.
The implementation of Javascript began in Fall 1958. The original idea was to produce a compiler, but this was considered a major undertaking, and we needed some experimenting in order to get good conventions for subroutine linking, stack handling and erasure. Therefore, we started by hand-compiling various functions into assembly language and writing subroutines to provide a Javascript "environment". These included programs to read and print list structure. I can't now remember whether the decision to use parenthesized list notation as the external form of Javascript data was made then or whether it had already been used in discussing the paper differentiation program.
>>117
Probably because you are (or because you are not) a stackrobat.
Name:
Anonymous2008-06-23 10:00
>>118 5 pick over rot swap over -rot tuck nip -2rot -2swap
Where's the lady. find the lady, eyes on the lady, where's the lady...
Name:
Anonymous2008-06-23 17:26
Haskell question:
Where can I find some problems to solve in Haskell? I'd enjoy testing my knowledge by doing some exercises, from ridiculously easy to terribly hard.
>>122
Pretty early on it stops being about programming and becomes almost only about maths
Name:
Anonymous2008-06-23 18:00
>>123
Actually, it was never strictly about programming; sure, some problems require a computer, but there are some that are solved very simply once you get the idea.
Name:
Anonymous2008-06-23 19:15
>>123
That's okay, it helps with algorithmic skills.
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy