ibKH 2017-03-03 02:01:34
hello i m learning haskell and i'm having difficult time understanding monoid, functor, applicative functor and monads. Can anyone suggest me link to a tutorial or some easy way to understand them
hpc 2017-03-03 02:03:38
ibKH: take it one thing at a time, and learn them in that order
oherrala 2017-03-03 02:03:38
ibKH: have you already found this: http://dev.stephendiehl.com/hask/ ?
oherrala 2017-03-03 02:04:22
ibKH: and this one: https://wiki.haskell.org/Typeclassopedia
ibKH 2017-03-03 02:05:13
the first one i haven't checked i'll look now thanks
dramforever 2017-03-03 02:11:01
ibKH: Are you trying to know 'What exactly *is* a functor'?
dramforever 2017-03-03 02:11:06
Don't do that
dramforever 2017-03-03 02:11:09
Just keep going
dramforever 2017-03-03 02:11:18
Things will make much more sense later on
Athas 2017-03-03 02:12:04
Man, "functor" gotta be the most overloaded term in computer science.
dramforever 2017-03-03 02:12:32
*If* you understand typeclasses, you know enough about monoid, functor, applicative to get going
dramforever 2017-03-03 02:12:48
(unrelated note: you mentioned functor twice :P)
hpc 2017-03-03 02:12:49
especially Monoid, which you probably know already and just don't know it yet
ibKH 2017-03-03 02:12:55
@dranforever yes, i know that is a mappable over a structure but that's it
lambdabot 2017-03-03 02:12:56
Unknown command, try @list
dramforever 2017-03-03 02:13:09
*If* you get do-notation desugaring you know enough about Monoid
dramforever 2017-03-03 02:13:16
ibKH: That's it
ski 2017-03-03 02:13:20
@where on-functors
lambdabot 2017-03-03 02:13:20
"On Functors" (in C++,Standard ML,Haskell,Prolog) by Peteris Krumins in 2010-05-17 at
dramforever 2017-03-03 02:14:04
If you don't find the meaning of functors, that's because there's no such meaning
dramforever 2017-03-03 02:14:30
ibKH: Do you know typeclasses?
ibKH 2017-03-03 02:14:36
yes
dramforever 2017-03-03 02:14:59
ibKH: And you've seen the typeclasses of those things?
dramforever 2017-03-03 02:15:11
Uh, sorry I meant monad
ibKH 2017-03-03 02:15:26
fmap and things like that ?
dramforever 2017-03-03 02:15:35
class Functor f where
ski 2017-03-03 02:15:43
or `(==)',`show',&c.
dramforever 2017-03-03 02:15:43
fmap :: (a -> b) -> f a -> f b
ibKH 2017-03-03 02:15:44
aa yes
dramforever 2017-03-03 02:15:49
ibKH: Thank you
dramforever 2017-03-03 02:16:03
You have learned functor, applicative, monad, etc.
ibKH 2017-03-03 02:16:39
ok so i need practice to know how to use them i guess
dramforever 2017-03-03 02:16:57
ibKH: To practice, keep going forwards
dramforever 2017-03-03 02:17:19
Don't struggle to understand them -- there isn't anything to understand
ibKH 2017-03-03 02:17:56
ok i ll try to use them in practice thanks.
SepakoRayl 2017-03-03 02:28:10
When using Alex with the monad wrapper, is runAlex supposed to return a single match ?
nbro 2017-03-03 02:29:21
if I define a function like this: k = 1; h k = True; h _ = False; why, if I call f 1, or f 2, I'm not the first pattern?
Ferdirand 2017-03-03 02:30:28
nbro: because of shadowing
nbro 2017-03-03 02:32:00
Ferdirand: how does it work exactly here? If I calll f k, it still returns False...
Ferdirand 2017-03-03 02:32:46
wait that should not even compile
Ferdirand 2017-03-03 02:32:55
it would complain of overlapping patterns
nbro 2017-03-03 02:34:27
Ferdirand: you're right, I was trying it on the interpreter...
nbro 2017-03-03 02:34:48
so f k = True should actually match anything
Ferdirand 2017-03-03 02:35:23
oh
Ferdirand 2017-03-03 02:35:23
then your second clause shadows the first as an entirely new function
nbro 2017-03-03 02:38:06
Ferdirand: yes
nbro 2017-03-03 02:38:35
btw, is it a good idea to say that a function returns a value?
nbro 2017-03-03 02:39:00
with respect to the word "returns"
nbro 2017-03-03 02:39:23
should I prefer for example "produces"?
nbro 2017-03-03 02:39:40
I know there's also the keyword return in Haskell, even though I've still not had a look at it
liste 2017-03-03 02:41:31
nbro: it's a function, not a keyword
liste 2017-03-03 02:41:31
:t return
lambdabot 2017-03-03 02:41:31
Monad m => a -> m a
nbro 2017-03-03 02:41:43
ahah, this bot is funny
nbro 2017-03-03 02:41:52
liste: ok
Ferdirand 2017-03-03 02:42:33
maybe "evaluates to" is more accurate, I don't know, let's ask the elders for their opinion
Logio 2017-03-03 02:42:37
nbro: I would prefer 'return' to 'produce' myself
dminuoso 2017-03-03 02:42:54
nbro: The book Im reading uses the word reduction actually.
ski 2017-03-03 02:44:41
nbro : "returns" or "outputs" is fine, imho
Logio 2017-03-03 02:44:50
if you feel like avoiding 'return', it's probably best to go towards the abstract math version of mapping values to values, instead of the intuitive 'doing stuff' to values interpretation
ski 2017-03-03 02:44:55
"produces" might work as well
Logio 2017-03-03 02:45:50
but that depends on what you want the reader to think about
ski 2017-03-03 02:46:02
one could say the function call evaluates or reduces to a result
nbro 2017-03-03 02:46:52
ok, at least saying "returns" it does not seem to be a sin
liste 2017-03-03 02:47:31
yeah, the "return" function is badly named anywahy
liste 2017-03-03 02:47:44
these days you can use "pure" instead of "return"
liste 2017-03-03 02:48:05
> do { putStrLn "hi"; pure 4 }
lambdabot 2017-03-03 02:48:08
nbro 2017-03-03 02:50:15
let me try to play also with this bot
ski 2017-03-03 02:50:29
@help run
lambdabot 2017-03-03 02:50:29
run . You have Haskell, 3 seconds and no IO. Go nuts!
nbro 2017-03-03 02:50:34
:t map
lambdabot 2017-03-03 02:50:36
(a -> b) -> [a] -> [b]
ski 2017-03-03 02:50:40
`> ...' short for `@run ...'
ski 2017-03-03 02:50:48
`:t ...' is short for `@type ...'
Tuplanolla 2017-03-03 02:51:25
You can send private messages to it as well, nbro.
nbro 2017-03-03 02:52:09
ahah, I saw the source code is hosted on Github, maybe I will have a look at it
liste 2017-03-03 02:53:26
> isGreat "liste" -- pm's with lambdabot rock
lambdabot 2017-03-03 02:53:29
yeah!
nbro 2017-03-03 03:01:57
:t toDegress x = x * 180.0 / pi
lambdabot 2017-03-03 03:01:59
error:
lambdabot 2017-03-03 03:01:59
parse error on input '='
lambdabot 2017-03-03 03:01:59
Perhaps you need a 'let' in a 'do' block?
Xnuk 2017-03-03 03:02:14
:t \x -> x * 180.0 / pi
lambdabot 2017-03-03 03:02:17
Floating a => a -> a
Xnuk 2017-03-03 03:02:43
> isGreat "Haskell"
lambdabot 2017-03-03 03:02:46
nah...
nbro 2017-03-03 03:02:55
ahah
Tuplanolla 2017-03-03 03:03:20
The documentation for `Control.Concurrent` says that "if you have a `ThreadId`, you essentially have a pointer to the thread itself".
fDev2179 2017-03-03 03:03:22
That's funny.
Tuplanolla 2017-03-03 03:03:57
Does this mean that if a thread dies and I start another one, it could get the now-unused `ThreadId` of the dead thread?
Tuplanolla 2017-03-03 03:05:20
This feels like the pid reaping problem all over again.
mauke 2017-03-03 03:07:18
Tuplanolla: what's the problem?
Tuplanolla 2017-03-03 03:08:25
You may accidentally kill the wrong thread, mauke.
mauke 2017-03-03 03:08:57
how so?
Tuplanolla 2017-03-03 03:15:03
Let's say I spawn threads #1, #2 and #3. Before #2 manages to start, #1 dies due to an exception. Now #3 may get the `ThreadId` of #1, so when I try to kill #1, which should do nothing, #3 dies instead.
Tuplanolla 2017-03-03 03:17:04
This is the stuff nightmares are made of.
mauke 2017-03-03 03:21:58
Tuplanolla: you can only kill #1 if you have its ThreadId
mauke 2017-03-03 03:22:11
if you have a ThreadId, you have a pointer to the thread
mauke 2017-03-03 03:22:17
if you have a pointer to it, it can't be garbage collected
mauke 2017-03-03 03:22:28
so it can't be reused
Tuplanolla 2017-03-03 03:22:32
Oh, of course!
vaibhavsagar 2017-03-03 03:33:50
I'm having insane memory usage on this program for the Coursera algorithms 1 course
vaibhavsagar 2017-03-03 03:34:02
is there a way to get around this?
vaibhavsagar 2017-03-03 03:34:14
http://lpaste.net/1337420848532815872
robertkennedy 2017-03-03 03:36:38
If I implement a class with a non transitive version of Eq, will my code work?
vaibhavsagar 2017-03-03 03:36:44
the input is roughly 1 million lines, and it all seems fine until I try to calculate the intersections
robertkennedy 2017-03-03 03:38:39
Ie will pattern matching literals use Eq? Probably not?
lyxia 2017-03-03 03:38:44
robertkennedy: maybe, if your code doesn't rely on transitivity.
lyxia 2017-03-03 03:39:09
pattern matching literals uses Eq
robertkennedy 2017-03-03 03:39:58
Oh tight
lyxia 2017-03-03 03:40:04
that sounds like a bad idea out of any context though
robertkennedy 2017-03-03 03:41:33
Well I'm thinking to represent computable numbers with equality on intervals
robertkennedy 2017-03-03 03:42:01
So I could say "1.66666 == 1.67"
robertkennedy 2017-03-03 03:43:01
Not intervals, maybe, but I just wanted to ensure I wasn't dead out of the gate
nbro 2017-03-03 03:43:19
I'm creating an "unhex" function that, given a character from '1' to 'f' (i.e. the hexadecimal characters) it returns the decimal representation… I'm enumerating all possible pattern matchings in different lines, like "…unhex 'c' = Just 12; unhex 'd' = Just 13; …". Is there a way to shorten this code?
Tuplanolla 2017-03-03 03:44:24
You can make use of `ord`, nbro.
Tuplanolla 2017-03-03 03:44:24
:t ord
lambdabot 2017-03-03 03:44:24
Char -> Int
mauke 2017-03-03 03:44:24
> digitToInt 'c'
lambdabot 2017-03-03 03:44:27
12
liste 2017-03-03 03:44:47
> digitToInt 'g'
lambdabot 2017-03-03 03:44:50
*Exception: Char.digitToInt: not a digit 'g'