fProgrammer 2017-02-23 00:49:01
quick question: I've two variables (say p, q) which are of type (Maybe A) and (Maybe B). I want to write a function which does something only when both p,q are not Nothing. I know I can use (isNothing) etc How do I write it concisely?
Axman6 2017-02-23 00:49:28
f <$> p <*> q
Axman6 2017-02-23 00:49:36
or liftA2 f p q
fProgrammer 2017-02-23 00:49:59
Axman6: umm lemme try, thanks!
Axman6 2017-02-23 00:50:01
(you will end up with a Maybe C assuming f :: A -> B -> C)
Axman6 2017-02-23 00:50:10
:t liftA2
lambdabot 2017-02-23 00:50:12
Applicative f => (a -> b -> c) -> f a -> f b -> f c
Axman6 2017-02-23 00:51:40
fProgrammer:you could also pattern match, that's pretty much always a better idea than uing something like isNothing, because it also gives a name to the value contained in the Just constructor if it exists. Applicative just abstracts this concept for you
ertes 2017-02-23 00:53:14
fProgrammer: you're only interested in whether they're Just, not the actual values?
fProgrammer 2017-02-23 00:53:36
ertes: interested in actual values only if they are Just
fProgrammer 2017-02-23 00:53:48
Axman6: how do I pattern match for two variables?
ertes 2017-02-23 00:54:26
fProgrammer: then what Axman6 said
Axman6 2017-02-23 00:54:28
case mA of Nothing -> Notjing; Just a -> case mB of Nothing -> Nothing; Just b -> Just (f a b)
Axman6 2017-02-23 00:54:44
but this is exactly what liftA2 does (and the applicative style version too)
fProgrammer 2017-02-23 00:55:01
Axman6: yes, Applicative seems nicer. Thanks anyway!
ertes 2017-02-23 00:55:05
> liftA2 (+) (Just 3) (Just 5)
lambdabot 2017-02-23 00:55:12
mueval-core: Time limit exceeded
Axman6 2017-02-23 00:55:15
lambdabot!
ertes 2017-02-23 00:55:18
lambdabot: you serious?
Axman6 2017-02-23 00:55:21
Y U NO
ertes 2017-02-23 00:55:24
> liftA2 (+) (Just 3) (Just 5)
lambdabot 2017-02-23 00:55:28
Just 8
ertes 2017-02-23 00:56:04
> liftA2 replicate (Just 4) (Just 'a')
lambdabot 2017-02-23 00:56:08
Just "aaaa"
ertes 2017-02-23 00:56:30
fProgrammer: then you can pattern-match on the result: case liftA2 f mx my of …
ertes 2017-02-23 00:56:37
or you can use 'maybe', which i usually prefer
fProgrammer 2017-02-23 00:56:50
ertes: understood!
ertes 2017-02-23 00:56:50
> maybe "d'oh!" show (Just 7)
lambdabot 2017-02-23 00:56:55
"7"
Cooler 2017-02-23 00:56:57
what is line 8 doing? http://lpaste.net/352903
ertes 2017-02-23 00:56:57
> maybe "d'oh!" show Nothing
lambdabot 2017-02-23 00:57:01
"d'oh!"
Axman6 2017-02-23 00:57:56
Cooler: that parsed exactly the string ": " and nothing else
Axman6 2017-02-23 00:58:01
parses*
Cooler 2017-02-23 00:58:15
what is string?
Axman6 2017-02-23 00:58:21
Cooler: also that code isn't correctly indented
Axman6 2017-02-23 00:58:38
string is a parser which you give a string and it succeeds if it parses exactly that string only
Cooler 2017-02-23 00:58:39
is that a function that creates a parser for a string?
Axman6 2017-02-23 00:58:43
yes
Cooler 2017-02-23 00:59:09
is that code from Aeson?
Axman6 2017-02-23 00:59:15
so string "XXX" will only succedd if it finds the string XXX in the input
Axman6 2017-02-23 00:59:25
I don't think anything there is from Aeson
mekeor 2017-02-23 01:24:46
is haskell growing or is it dying? what's your impression? my personal impression is that at least the activity of this irc channel has been decreasing.
marekw2143 2017-02-23 01:25:30
how can I install GHC.Exts ?
liste 2017-02-23 01:25:52
mekeor: it's growing, the IRC channel represents a minorish part of the community
M2tias 2017-02-23 01:26:11
mekeor: maybe irc is just dying. haskell was #1 programming language for sunday programmers according to stackoverflow
mekeor 2017-02-23 01:27:20
i see. bummer. irc is nice :(
lyxia 2017-02-23 01:27:44
marekw2143: it's part of base, you don't need to install it
mekeor 2017-02-23 01:30:49
mekeor: for the record, see https://stackoverflow.blog/2017/02/What-Programming-Languages-Weekends/
patrick_1 2017-02-23 01:36:39
morning everyone
mekeor 2017-02-23 01:36:57
hello patrick_1 :)
ertes 2017-02-23 01:38:02
we should take the opportunity to create a replacement for IRC that isn't brain-damaged
liste 2017-02-23 01:38:13
ertes: IRCv3 ?
hpc 2017-02-23 01:38:48
usenet?
mekeor 2017-02-23 01:39:36
ertes: http://about.psyc.eu/ -- it's good!
Ferdirand 2017-02-23 01:39:46
or silc ? xmpp ? signal ? tox ?
mekeor 2017-02-23 01:39:50
let's write a client for that protocoll
Tuplanolla 2017-02-23 01:41:24
Which one supports code and equation rendering?
lyxia 2017-02-23 01:42:02
Let's communicate in LaTeX over email.
mekeor 2017-02-23 01:42:40
"PSYC is, as benchmarks show, the fastest yet extensible text-based protocol we are aware of, providing a messaging infrastructure for human conversation and social exchange of possibly binary data"
mekeor 2017-02-23 01:43:27
let's communicate over letters. would you like to give me your address?
ertes 2017-02-23 01:43:35
mekeor: sounds promising actually… IRC is crap for many reasons, XMPP is crap for all the other reasons, etc.