« first day (289 days earlier)      last day (91 days later) » 

8:42 PM
First!
 
> the state monad gives you (>>=) to chain together functions that look essentially like :: a -> s -> (a,s) into a single function :: s -> (a,s).
^ Hm, makes sense.
 
What if I have an IO String and I want to convert it to an Int to pass it to a function that takes an Int? This gives a compiler error:
main :: IO ()
main = do
    valueStr <- getLine
    value <- read valueStr :: Int -- Couldn't match expected type `IO t0' with actual type `Int'
    putStrLn $ (show value) ++ " ^ 2 = " ++ (show $ sq value)

sq :: Int -> Int
sq x = x * x
 
Conceptually representing computations.
 
Xeo
@CatPlusPlus three?
 
sbi
@FredOverflow If you cannot explain a concept in a few well-chosen sentences, it might not be all that good a concept.
 
8:45 PM
Well, two core ones and fail.
@sbi What's not easy about my explanation? :<
@RadekSlupik <- is monadic bind. read is a pure function.
You want let value = read valueStr :: Int.
 
Xeo
@CatPlusPlus What's fail for?
 
So it will execute read as late as possible then?
 
@Xeo Pattern matching failure hack or something like that.
 
Xeo
okay ...
aka not all that important?
 
@RadekSlupik You don't care when pure functions are executed in Haskell, because it doesn't matter.
 
8:47 PM
@RadekSlupik It'll be ready when it needs to be ready!
 
Oké. :3
 
fail is one of Haskell's few fails.
 
Now that I have a rough understanding of monads, I like Haskell a bit more.
 
what is Haskell's main selling point?
 
@nightcracker Being Haskell.
 
sbi
8:48 PM

Haskell

concatMap = ((.).(.)) concat map
 
Well, I'm there, but nobody else is.
 
@CatPlusPlus: ...
 
@nightcracker No, but really, extremely powerful type system, nice syntax.
Very expressive.
Template Haskell.
 
How are the bindings to C and such?
for example, using OpenGL from it
 
@nightcracker FFI is part of the core language spec.
 
8:51 PM
C functions can be used from FFI, IIRC.
 
sbi
34 messages moved from Lounge<C++>
 
PEOPLE.
 
lolz
 
IN THE HASKELL ROOM.
 
8:52 PM
:D
How does OpenGL go with haskell
seeing that OpenGL is as state based as state based can get
 
It runs in IO.
 
Monads!
 
I guess I'll continue reading the book
 
@nightcracker and writing programs.
 
I'm not at my own PC, so can't try out much =/
 
8:54 PM
ideone.com
 
ideone has old GHC, don't bother.
 
@nightcracker tryhaskell.org
@nightcracker What book?
 
arguments are passed by a space seperated list
 
great book
 
I think I was going on about ST and STM before you distracted me.
 
8:57 PM
so min 9 10
 
but min min 10 applies min to min
 
Function application binds from left and has the most precedence, so yes.
 
(on a 1 element list, so not very useful, but ok)
 
min min 10 calls min with two arguments, min and 10.
It won't ever compile, so you'll notice it quickly. :P
 
8:59 PM
@nightcracker Well, Haskell functions only take 1 argument, but function application is left-associative, so f a b c means ((f a) b) c.
 
Yes, currying. Currying is wonderful.
 
so
min 8 10
calls min 8
and the result from that is called with 10?
 
and the result is some sort of what in C++ would be a "proxy object"
 
In Python, it'd be min = lambda x: lambda y: fancy min expression.
 
9:01 PM
if I look at its value it would be 8
 
And min(8)(10)
The result is just a function.
 
@nightcracker min x = \y -> if (x < y) then x else y or something.
 
min has signature a -> a -> a. Applying one argument yields a function a -> a. Applying another yields result a.
 
what magic is done to actually retrieve the minimum value?
instead of the function to calculate further
 
Last function in that chain returns a value.
Nothing magical.
 
9:05 PM
"putting something at the end of a list that's fifty million entries long is going to take a while. However, putting something at the beginning of a list using the : operator (also called the cons operator) is instantaneous. "
that's strange
usually it's the exact opposite
 
not with singly linked lists
 
It's not just singly linked list, it's a recursive list.
 
(x : xs) reuses the list xs as its tail
 
To append at the end, you have to recursively descend into the last tail, and put the value there.
 
haskell surely uses some unknown syntax for me
indexing with !!?
lol
 
9:06 PM
Indexing with !.
 
It's just an operator.
 
Haskell has a great syntax.
 
Also, you shouldn't use it on lists.
 
"If you want to get an element out of a list by index, use !!."
 
Also, in a decent language indexing is not terribly useful outside of maps.
 
9:07 PM
from the book
 
Yes, but you shouldn't do that.
 
It's O(n) in lists. There are arrays/vectors if you want to use indexing.
 
ahh now I understand "recursive" lists
"tail takes a list and returns its tail. In other words, it chops off a list's head."
 
You understand pretty quickly.
 
9:10 PM
List is quite literally data [] a = [] | (:) a [a].
 
yeah that has no meaning to me whatsoever, as of yet
 
data List a = Nil | Cons a (List a)
 
> A list is either empty, or it is one element followed by a list.
 
You can see the recursion from definition.
 
@CatPlusPlus You should print that on a T shirt.
 
9:11 PM
I got the english version
 
Functional languages prefer that form to linked lists (especially doubly-linked ones), because it's easier to process recursively.
 
I mean, the syntax is mostly gibberish for me right now
I presume | is or
 
And recursion is what functional languages do.
It's an algebraic data type.
 
@nightcracker Right, | separates possible data constructors.
 
Think union.
 
9:12 PM
data Maybe a = Nothing | Just a
 
But without the type mixing?
 
Discriminate tagged union. Like boost::varaint<T>.
 
never used boost::variant
 
Shame on you.
 
(I almost never use C++)
 
9:13 PM
I can't think of Python equivalent, because it's not really used in Python.
 
data Shape = Triangle height | Circle radius | Rectangle width height
 
I think you need a bit more than just the height in a triangle :)
 
maybe :)
 
unless you mean a 90 - 45 - 45 one
 
I prefer 60 60 60
No wait, I prefer 90 60 90, but that's not for triangles ;)
 
9:14 PM
I prefer 69
you know what I love?
Python slices
min doesn't take a list?
because the book also talks about minimum.
 
min :: Ord a => a -> a -> a
minimum :: Ord a => [a] -> a
Use min if you have two elements and minimum if you have a list.
 
@nightcracker There's splitAt, take, drop and stuff.
 
because Python is so dynamic I cansay
min(3, 4)
 
And tail! tail is a slice too!
 
or min([3, 4, 5])
 
9:18 PM
slice a b = take b . drop a
Or something.
 
how is Haskell's performance?
 
@nightcracker You can do that with typeclasses if you want. Probably not worth the trouble.
 
because all this recursion seems... expensive
 
Languages don't have performance, silly.
 
fine
 
9:19 PM
GHC is pretty good.
 
Haskells canonical implementation
assuming that exists
 
GHC is on par with GCC.
 
@nightcracker Don't worry. Your mind is tainted.
 
is it?
 
There are things about Haskell that are not-so-trivial to predict when it comes to performance, but there are ways to deal with that, when you're at the point where you should care.
For learning, completely irrelevant.
 
9:20 PM
@nightcracker If you're worried about "all this recursion", it is.
 
@R.MartinhoFernandes I think it'd need fundeps.
 
If you're worried about performance of lists, you can also use mutable arrays within the IO monad. Sadly, last time I checked, they were about 100x slower :)
 
"To make a list with all the numbers from 20 to 1, you can't just do [20..1], you have to do [20,19..1]."
why?
 
Because otherwise Haskell thinks you want to count upwards.
 
9:21 PM
and why does it think I want to count downwards in the second case?
 
Because it infers from 20,19 that you want to count by -1.
 
:(
why doesn't it simply check if in the range x < y
when [x..y]
 
class CanMinimum a b | a -> b where
    minimum :: a -> b
instance (Ord a) => CanMinimum [a] a where
    minimum = Data.List.minimum
instance (Ord a) => CanMinimum (a, a) a where
    minimum = uncurry Prelude.min
I'm afraid to try.
 
@nightcracker I don't know, that's just how the language is defined. Personally, I almost never use [x..y].
 
also, I assume all ranges in haskell follows Dijkstra's recommendation?
 
9:24 PM
@nightcracker Because that would add unnecessary requirements.
 
lower <= range < upper
 
It would require Ord a, Enum a, instead of simply Enum a.
 
@R.MartinhoFernandes: I don't see why.
 
Not all types support <.
 
@nightcracker No, [1..10] includes 1 and 10.
 
9:25 PM
@FredOverflow: ;(
@R.MartinhoFernandes: yet it is still used for [20,19..1]
 
@nightcracker It isn't.
Enum has all that is needed.
 
I have no idea what Enum and Ord are, btw
 
Haha, it compiles.
 
I can make guesses, but those usually don't go in programming.
 
Only needs three extensions.
 
9:26 PM
@nightcracker Typeclasses.
Sets of functions supported by types.
 
Is Data.DateTime always available? I get a not-found error when I import it. :/
 
The [x, y .. z] syntax only requires implementing the functions in Enum.
 
Doesn't work with that tuple, though. Oh well.
 
Wait
 
@RadekSlupik It's in datetime package.
 
9:27 PM
[x, y .. z] is a syntactically different statement than [x, y, z, blablabla]?
 
oh
I was thinking free mix 'n matching
 
@CatPlusPlus Ah, thanks. Adding it to my cabal file fixed the problem.
 
[3, 6..8, 20, (-5)..40]
to name something
 
9:28 PM
@nightcracker Then you couldn't use other steps.
For example, you can do [0, 2 ..] to get a list of all the even numbers.
 
@nightcracker [[3], [6..8], [20], [(-5)..40]]
 
OHHHHHHHH
 
@CatPlusPlus ^D'd.
 
@CatPlusPlus Hmm, no.
 
Oh, right.
 
9:30 PM
The step is defined in [x, y..z] as y-x?!
 
err
of course
 
@nightcracker Depends on the type. But that's the general idea.
 
ahh
@CatPlusPlus: but that creates multiple lists in lists
 
9:31 PM
@CatPlusPlus: which would require "flattening" to get what I would've meant
 
If you want one flat list, just concat it.
 
if my original meaning made any sense in the first place
 
Personally, I wouldn't worry too much about this [x,y..z] business. It's not really one of the things in Haskell that blow your mind :)
 
ok now I get it
 
Well, it would have to autoflatten, and I don't see it being very useful anyway.
 
9:32 PM
Perl!
The pain.
 
well
in Perl
at least the characters don't overlap
I was used to this notation in Python
range(start, stop, step)
but I'm starting to smell that I need to drop all Python associations in this language
 
enumFromThenTo
 
If it was the same, it wouldn't be worth learning.
 
That's what [x,y..z] desugars to.
 
is Haskell a "large" language?
 
9:35 PM
range start stop step = enumFromThenTo start (start+step) stop
 
for example C is quite small
 
^ there you go then :)
 
C++ is ridiculously big (with all the details and specifiers and other bs)
 
@FredOverflow Oh god, you broke it!
 
Python is quite small but the standard library is big
 
9:35 PM
Now it requires Num a, Enum a.
 
Haskell is probably smaller than C.
 
@CatPlusPlus What? Are you sure?
 
It's simpler for sure.
~150 pages of the language description.
C11 ~200.
 
And C has more? Stupid Internet delay.
 
Wide is simpler than both.
 
9:38 PM
It's a rough estimate.
 
Ell
@CatPlusPlus explicit is better than implicit? Aren't most of haskells types inferred? aka implicitly.. discovered? Or do you mean about type conversions/casts?
 
The whole Haskell spec is ~300 pages, the whole C11 is ~700.
 
type inferring doesn't remove explicitness
if implemented well
a = 5 is just as explicit as int a = 5
x = vec.begin() is just as explicit as std::vector<int>::iterator x = vec.begin()
that is, assuming that you know what vec.begin() is
and if you didn't you're doing something wrong :)
 
@Ell Type inference is a wonderful thing.
 
Ell
but it's implicit, right? you don't excplicitly state the type .e.h int a; the types are inferred (implicit) e.g. a = 5;
meh I'm argueing for no reason. Haskell is gross anyway I'm going back to the android/c++ rooms :L
 
9:41 PM
Lol weakling.
 
You do explicitly state the name of the type.
 
@Ell @Domagoj used to say the same... Then he gave it chance.
 
If Haskell is gross then Android is bottom of sewage.
 
why doesn't this work?
isodd x = x % 2 == 0
(and yes I know of odd)
<hint>:1:9: parse error on input ='`
 
does Haskell even have %?
 
9:42 PM
Are you in GHCi?
 
I'm just trying it out here: tryhaskell.org
 
@FredOverflow Yes, for Rational.
 
(not on my own PC)
 
@FredOverflow It's mod.
 
(%) :: Integral a => a -> a -> Ratio a
 
9:42 PM
still got an error
 
Use let isodd x = x mod 2 == 0.
 
isodd x = x mod 2 == 0
 
Ell
I have tried haskell, but it is too intelligent for me
 
let isodd x = x `mod` 2 == 0
 
why do I need let?
 
9:43 PM
@nightcracker Parse error is that interpreter limitation.
 
@nightcracker Interactive shells usually need it. You don't it in real code.
 
@nightcracker GHCi requires it for functions, I don't know why.
 
let isodd x = x `mod` 2 == 0
not an expression: `let isodd x = x `mod` 2 == 0'
 
Maybe tryhaskell isn't that great, dunno :)
 
% ghci
GHCi, version 7.4.1: haskell.org/ghc  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> let isodd x = x `mod` 2 == 0
Prelude>
Works in GHCi.
 
9:44 PM
GHCi embeds that in IO.
 
oh well
 
Tryhaskell probably doesn't embed it in a do expression.
 
got to go
nice speaking to you guys. See you later!
 
Später!
 
Do let isodd x = ... in isodd 2
 
9:44 PM
later :)
 
Wait. If x mod 2 == 0, isn't x even?
It should be iseven then, not isodd.
 
Math. Not even once.
 
@RadekSlupik Another German? :)
 
@FredOverflow Dutch. :P
The Dutch word is “later”, but that sounds so English.
Thank God Haskell uses = and == and not := and =.
 
I would have liked the latter better...
 
9:50 PM
heh :p
 
@FredOverflow Yeah, me too.
 
Or, if possible, use = for both, but that's probably the BASIC programmer in me :)
 
I don't like = for comparison; = in mathematics means that both sides are equal. The point of comparison is that you are not sure if they are equal or not.
 
/= sucks, though.
 
Is that not equals?
 
9:52 PM
Yes.
 
(!=) a b = a /= b :<
 
a != b = a /= b
 
a ≠ b = a /= b
 
@RadekSlupik How about guards in mathematics? Those just test.
 
@R.MartinhoFernandes omg Haskell is so awesome.
 
9:54 PM
Lol.
 
You know, you guys are making me lose my edge. That sucks.
(≠) = (/=) -- fixed
 
Lol.
Pointfree robot.
 
(∅) = []
 
The empty set is not a function.
Also, (==∅) isn't that long.
 
Can you even define unary operators?
 
9:56 PM
I suck at maths.
@CatPlusPlus Well it worked, and so do nullary operators:
Prelude> let (∅) = []
Prelude> (∅)
[]
Though an empty list != an empty set, is it?
 
Representation details.
 
@RadekSlupik Meet nub, the set maker.
 
Noob.
nub cracks me up every time I see it. That name is so ridiculous.
 
I'm going to bed.
brb
 
@CatPlusPlus What does it stand for, anyway?
 
9:59 PM
Essence.
 
@FredOverflow "(The name nub means `essence'.)"
They even preemptively put it in the docs.
 
nub (x:xs) = x : nub (filter (/= x) xs) or something?
 
(x:xs) that is head and tail, right?
 
It's a list pattern.
It dissects lists without mercy.
 
10:05 PM
Only lists with at least one element, though ;)
 
Nobody cares about those poor empty lists.
 
No mercy for empty lists.
 
Empty lists are inobservable; they have a zero size.
 
Empty lists are both lists and empty.
 
10:13 PM
What is the type of []? :)
a => [a] probably?
 
[] a
Or [a], for you fat sugar-loving types.
Just [a], no constraints.
It's fully polymorphic.
 
a is not a valid constraint anyway.
 
Is Haskell type like typedef in C++ or more like type in Go?
 
Oh yeah, that also annoys me about Haskell.
 
10:28 PM
Oh. Meh.
 
10:44 PM
But we also have newtype for a "strong typedef".
 
Ganz geil!
 

« first day (289 days earlier)      last day (91 days later) »