

Try Haskell: An interactive tutorial in your browser - niggler
http://tryhaskell.org/#

======
daGrevis
I have read some tutorials about Haskell (to be completely honest, 60% of
"Learn haskell for great good" twice). Still, I need to stop and think for few
seconds to write something in it.

~~~
DanWaterworth
It does take a while, but, for me at least, it did eventually become natural.

------
hp50g
I've been through this a few times. It puts me off Haskell even more each
time.

Bear in mind I'm pretty handy with obscure obfuscated by default things like
RPL, Forth and Perl and occasionally common lisp.

~~~
tome
> It puts me off Haskell even more each time.

How come?

~~~
hp50g
It's not the tutorial specifically - more Haskell itself:

Syntax feels slightly horrid. Doesn't seem to visually or syntactically scale
well with the size of the problem at hand. Some of it is plain ugly (records).
It's harder than the others resulting in more head scratching. Debugging is
slightly painful.

These are all IMHO.

To be fair, I'm going to do the tutorial again this afternoon.

~~~
dons
What do you mean "syntax doesn't syntactically scale" ?

~~~
hp50g
A single function/expression tends to drag over too much space for my liking.
It's hard to break down some of them into functional units that fit in my head
properly. Perhaps I'm just thick :)

Look at List.hs (sort/sortBy) for what I mean:

[http://hackage.haskell.org/packages/archive/base/latest/doc/...](http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Data-
List.html)

~~~
pilgrim689
That sortBy is split into 6 sub-functions, all 2 to 4 lines each. You want it
more broken down?

~~~
hp50g
Fair point. I will do the tutorial again! :)

I might get it if I keep trying.

(ironically I did an engineering degree which was rather maths heavy so I
should get this).

------
sek
Make an interactive tutorial for monads. After 5 articles about it, who were
all very different, I still don't know how to code one.

~~~
merijnv
The majority of monad "tutorials" are notoriously terrible. Have you read "You
Could Have Invented Monads! (And Maybe You Already Have.)"? If no, you should
try it, it's a rather nice article. If yes, where did you get stuck with
trying to implement your own?

~~~
merijnv
Bah, I just noticed I completely forgot to include the link for the lazy:
[http://blog.sigfpe.com/2006/08/you-could-have-invented-
monad...](http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-
and.html)

------
CJefferson
Ooo, let's try something functional:

    
    
        > map reverse
    
        No instance for (GHC.Show.Show ([[a0]] -> [[a0]]))
        arising from a use of `M1690418375.show_M1690418375'
        Possible fix:
        add an instance declaration for (GHC.Show.Show ([[a0]] -> [[a0]]))
    

Hmm....

~~~
pilgrim689
This tells you that "map reverse" returned a function that takes a list and
returns a list. This function does not have a "Show" instance (analogous to
someone failing to implement the "toString()" method for that type), so an
error is thrown at you since it cannot possibly output something that doesn't
know how to be output. Try just storing it in a variable instead.

> let f = map reverse

> f [[1,2,3], [6,7,8]]

EDIT: scratch the "let" example (thanks nandemo), tryhaskell.org doesn't
support that. my bad!

~~~
nandemo
That works on ghci but, unfortunately, Try Haskell doesn't seem to support
_let_.

~~~
jonke
TryHaskell uses <http://hackage.haskell.org/package/mueval> and not ghci You
can eval expression so following works let t ="foo" in t

~~~
nandemo
Yeah, I saw that it uses _mueval_ , but it's still conceivable that TryHaskell
itself could hack support for _let_ on top of it. Apparently Chris planned to
do it [1].

Note that in "let t=bar in foo" the scope of _t_ is restricted to _foo_ , so
the example above still doesn't work.

[1]
[http://www.reddit.com/r/haskell/comments/b58rk/try_haskell/c...](http://www.reddit.com/r/haskell/comments/b58rk/try_haskell/c0l0xdc)
([deleted] = Chris Doner)

~~~
jonke
Fair enough but you could do let f = map reverse in f ["ab", "cd"]

IMHO the tryhaskell expose more or less only simple pure functions and I doubt
that anyone with a real interest in haskell will get any substantial out of
it. However if one is completely new to programming maybe TryHaskell and these
6 short lessons have a value.

~~~
nandemo
Agreed.

Incidentally, Chris Doner has been producing far more exciting things like
Fay, so I'm not gonna complain about TryHaskell.

------
DodgyEggplant
<http://book.realworldhaskell.org/read/>

~~~
danieldk
Obligatory LYAH link :):

<http://learnyouahaskell.com/>

I gave this book to a lot of programmer friends, and most were very
enthusiastic after finishing the book. Even if you never use Haskell in the
real world, learning its abstractions makes you a better programmer (and
sometimes annoyed by the lack of type system features in other languages ;)).

------
hartator
You constructed a list!

Well done, that was tricky syntax. You used the (:) function. It takes two
values, some value and a list, and constructs a new list out of them. We call
it 'cons' for short.

No it's not:

> 'a' : [] => "a"

~~~
kryptiskt
What's the problem? A string in Haskell is a list of chars[1]. So you can
construct a string by consing chars to an empty list. Or is there something
else you object to?

[1] Which incidentally is a reason to avoid using it for anything serious.
Text is the better representation of text, and ByteString is better for
everything else.

------
esalman
Throws a bunch of jQuery errors in Firefox Aurora. Works OK in Chrome.

