Search Haskell Channel Logs

Monday, February 20, 2017

#haskell channel featuring liste, lambdabot, srhb, barrucadu, MarcelineVQ, Xnuk,

qmm 2017-02-20 19:52:33
what happens when you have have these two lines in a file?
qmm 2017-02-20 19:52:33
import qualified Database.Persist as DB
qmm 2017-02-20 19:52:36
import qualified Database.Persist.Postgresql as DB
qmm 2017-02-20 19:53:06
all of the functions Persist.Postgresql are now available through DB?
barrucadu 2017-02-20 19:53:06
You can refer to things from Database.Persist and Database.Persist.Postgresql as DB.
barrucadu 2017-02-20 19:53:21
If the name is defined in both modules, the compiler will yell at you
qmm 2017-02-20 19:53:26
what happens if there is a function in Persist with the same name as a function in Persist.Postgresql?
qmm 2017-02-20 19:53:36
oh
qmm 2017-02-20 19:53:39
thanks barrucadu
c_wraith 2017-02-20 19:58:42
Cooler: it sends an asynchronous exception to the thread doing the evaluation
c_wraith 2017-02-20 19:59:18
Cooler: but... receiving asynchronous exceptions is actually cooperative. It's only done when the running thread checks to see if there are any exceptions waiting
c_wraith 2017-02-20 19:59:35
Cooler: that check is done on allocations
c_wraith 2017-02-20 19:59:57
Cooler: but evaluating that expression only does two allocations total. After that, it spins without allocating
c_wraith 2017-02-20 20:00:28
Cooler: so the exception never has a chance to get delivered
qmm 2017-02-20 20:09:22
> fmap (maybe (Just "foo") read) Nothing
lambdabot 2017-02-20 20:09:26
Nothing
qmm 2017-02-20 20:09:38
> fmap (maybe (Just "foo") read) (Just "foo") -- fails, why? also hello!
lambdabot 2017-02-20 20:09:41
error:
lambdabot 2017-02-20 20:09:41
• Couldn't match type '[Char]' with 'Maybe String'
lambdabot 2017-02-20 20:09:41
Expected type: Maybe (Maybe String)
Xnuk 2017-02-20 20:14:55
:t fmap (maybe (Just "foo") read)
lambdabot 2017-02-20 20:14:57
Functor f => f (Maybe String) -> f (Maybe [Char])
Xnuk 2017-02-20 20:15:18
:t maybe (Just "foo") read
lambdabot 2017-02-20 20:15:20
Maybe String -> Maybe [Char]
Xnuk 2017-02-20 20:15:57
> (maybe (Just "foo") read) (Just "foo")
lambdabot 2017-02-20 20:16:00
*Exception: Prelude.read: no parse
Xnuk 2017-02-20 20:16:57
qmm: ^
Xnuk 2017-02-20 20:17:38
:t fmap
lambdabot 2017-02-20 20:17:41
Functor f => (a -> b) -> f a -> f b
qmm 2017-02-20 20:26:11
how does (Just "Just\"foo\"") have type f (Maybe String) ?
srhb 2017-02-20 20:26:59
It does not.
MarcelineVQ 2017-02-20 20:27:01
it doesn't, I didn't fmap
Xnuk 2017-02-20 20:27:05
qmm: it's Maybe String
qmm 2017-02-20 20:27:35
aha
qmm 2017-02-20 20:28:11
wait
qmm 2017-02-20 20:28:31
Just = f ?
srhb 2017-02-20 20:28:40
No, Just isn't a type
srhb 2017-02-20 20:28:48
It's a value constructor.
srhb 2017-02-20 20:28:56
It does signify that the f in question is Maybe
srhb 2017-02-20 20:29:06
(Since it's one of the value constructors of Maybe)
qmm 2017-02-20 20:29:18
so f = Maybe
srhb 2017-02-20 20:29:20
Yes.
qmm 2017-02-20 20:29:42
but it derives that from knowing Just that Just is value constructor in the Maybe class
srhb 2017-02-20 20:29:49
Yes.
qmm 2017-02-20 20:29:50
in the Maybe data constructor
qmm 2017-02-20 20:29:53
sorry
srhb 2017-02-20 20:30:03
No need to be sorry. :)
srhb 2017-02-20 20:30:50
:-)
qmm 2017-02-20 20:30:50
Just = Maybe = f, "Just\"foo\"" is the Maybe String?
srhb 2017-02-20 20:30:50
Actually, data constructor is wrong too.
srhb 2017-02-20 20:30:51
data constructor is synonymous to value constructor
srhb 2017-02-20 20:30:58
Maybe is a *type* constructor
liste 2017-02-20 20:30:59
Just is constructor for Maybe type
qmm 2017-02-20 20:31:10
oh right
qmm 2017-02-20 20:31:14
sorry again
srhb 2017-02-20 20:31:31
qmm: I didn't understand your last question, can you elaborate?
qmm 2017-02-20 20:31:48
:t fmap (maybe (Just "foo") read)
lambdabot 2017-02-20 20:31:51
Functor f => f (Maybe String) -> f (Maybe [Char])
qmm 2017-02-20 20:32:00
it takes an f (Maybe String)
qmm 2017-02-20 20:32:03
the f is the Maybe
srhb 2017-02-20 20:32:04
Right.
srhb 2017-02-20 20:32:06
No
srhb 2017-02-20 20:32:08
Not yet.
qmm 2017-02-20 20:32:10
oh
srhb 2017-02-20 20:32:12
It's more general than that.
srhb 2017-02-20 20:32:40
It's only when you gave it a Maybe (Maybe String) as argument you had to pick f ~ Maybe
srhb 2017-02-20 20:32:46
Let's start one simpler.
srhb 2017-02-20 20:32:57
:t maybe (Just "foo") read
lambdabot 2017-02-20 20:32:59
Maybe String -> Maybe [Char]
srhb 2017-02-20 20:34:17
If we *fmap* that over some f a, we can pick any f.
srhb 2017-02-20 20:34:26
(where the a matches, at least)
srhb 2017-02-20 20:34:39
For instance, IO, [], ...
srhb 2017-02-20 20:35:02
If you fmap that over a Nothing, you've picked a specific f, namely Maybe.
srhb 2017-02-20 20:35:43
What I'm saying is that you could replace `maybe (Just "foo") read` with any other a -> b, and it would not change the logic at all.
srhb 2017-02-20 20:35:53
:t fmap undefined Nothing
lambdabot 2017-02-20 20:35:55
Maybe b
srhb 2017-02-20 20:35:58
See?
qmm 2017-02-20 20:36:23
i see
srhb 2017-02-20 20:36:46
And we get back the parametricity over the Functor with...
srhb 2017-02-20 20:36:48
:t fmap undefined
lambdabot 2017-02-20 20:36:51
Functor f => f a -> f b
srhb 2017-02-20 20:36:59
Because we didn't pick an `f` yet.
qmm 2017-02-20 20:38:07
> fmap (\x -> x) Nothing
lambdabot 2017-02-20 20:38:10
Nothing
qmm 2017-02-20 20:38:15
> fmap (\x -> x) (Just 3)
lambdabot 2017-02-20 20:38:18
Just 3
qmm 2017-02-20 20:38:28
okay, i'm not going crazy
qmm 2017-02-20 20:38:32
just checking
srhb 2017-02-20 20:38:36
A little crazy is ok. :-)
qmm 2017-02-20 20:42:45
srhb: i guess i'm not understanding why (Just "Just\"foo\"") is f (Maybe String) still
srhb 2017-02-20 20:43:39
It's still not.
srhb 2017-02-20 20:43:46
So that's ok :)
srhb 2017-02-20 20:43:51
It's Maybe String
qmm 2017-02-20 20:43:57
i think i get it
MarcelineVQ 2017-02-20 20:44:06
your original problem combined 3 interesting problems people run into all at once so it's tougher to dissect :> "why didn't read parse" "how does maybe work" "what's happening with fmap here"
qmm 2017-02-20 20:44:06
fmap over Just makes the f a Maybe
srhb 2017-02-20 20:44:19
fmap maybe does, yes!
srhb 2017-02-20 20:44:34
That's why you get two layers.
srhb 2017-02-20 20:44:54
:t fmap (maybe undefined undefined) Nothing
lambdabot 2017-02-20 20:44:57
Maybe b
srhb 2017-02-20 20:45:03
:t fmap (maybe Nothing undefined) Nothing
lambdabot 2017-02-20 20:45:07
Maybe (Maybe a)