Search Haskell Channel Logs

Monday, February 6, 2017

#haskell channel featuring thatguy, geekosaur, merijn, dramforever, dibblego, lyxia, and 6 others.

c_wraith 2017-02-05 23:45:31
a bind really isn't an expression, though.
cocreature 2017-02-05 23:45:31
merijn: calling "x <- y" an expression seems weird
lyxia 2017-02-05 23:45:33
but then it gets confusing because "expression" means a lot of things
cocreature 2017-02-05 23:45:50
sure you can call everything an expression but then you lose a useful distinction
dramforever 2017-02-05 23:46:25
it's officially called a 'statement'
merijn 2017-02-05 23:47:12
dramforever: You appear to have a 5 minute lag ;)
dramforever 2017-02-05 23:47:34
Uh, maybe
merijn 2017-02-05 23:47:38
I don't like distinguishing do notation to begin with
cocreature 2017-02-05 23:48:08
that's fine but there _is_ a distinction in the expressions allowed in do notation and the expressions allowed elsewhere
merijn 2017-02-05 23:48:24
cocreature: In what sense?
cocreature 2017-02-05 23:48:45
merijn: "let x = y" is not a valid expression outside of do notation, "x <- y" is not a valid expression outside of do notation
dibblego 2017-02-05 23:49:15
x <- y works in a list comprehension
geekosaur 2017-02-05 23:49:32
so does the truncated let iirc
geekosaur 2017-02-05 23:49:41
but then a list comp is really just a condensed do
dramforever 2017-02-05 23:50:05
I would appreciate it if you would call it a 'statement', or maybe just recognize that there are valid syntactic constructs that don't really have values
dramforever 2017-02-05 23:50:09
How's my lag?
cocreature 2017-02-05 23:50:34
merijn: you can ofc come up with a different name for the things allowed in do notation but I don't think "statement" is that bad
merijn 2017-02-05 23:50:54
dramforever: But you can't have valid syntactic constructs that don't have values, as, for example a do block consisting of "x <- y" is a syntax error
dramforever 2017-02-05 23:51:33
Why
lyxia 2017-02-05 23:51:47
well it's valid as a statement
dramforever 2017-02-05 23:51:51
'x <- y' is a valid statement (as in do-notation)
dramforever 2017-02-05 23:52:27
https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-470003.14
merijn 2017-02-05 23:52:31
dramforever: It's only valid syntatically if followed by something else
merijn 2017-02-05 23:53:01
Anyway, we are now drifting into a more pedantic discussion then I intended :)
dramforever 2017-02-05 23:53:48
I suppose we are not thinking in the same direction
lyxia 2017-02-05 23:54:22
dramforever: each is pretty nice!
dramforever 2017-02-05 23:54:28
You know, we can't talk about words that don't make complete sentences and still make some sense
dramforever 2017-02-05 23:54:45
lyxia: Oh, that's... actually what I was going to ask you guys about
dramforever 2017-02-05 23:54:56
lyxia: Thank you
dramforever 2017-02-05 23:55:09
But I'm sort of... stuck now
lyxia 2017-02-05 23:55:42
oh?
dramforever 2017-02-05 23:56:01
Because as you can see it supports only a few syntactic constructs
dramforever 2017-02-05 23:56:30
Literally just one useful thing called 'function application'
dramforever 2017-02-05 23:56:50
And I'm so far unable to figure out how to extend it to case, let, lambda, etc.
dramforever 2017-02-05 23:57:31
And that is what I wanted advice on.
dramforever 2017-02-05 23:57:43
But did you just say it's 'pretty nice'?
dramforever 2017-02-05 23:58:00
lyxia: ^
dramforever 2017-02-05 23:58:40
hmm my lag seems fine :)
lyxia 2017-02-05 23:58:59
I did
dramforever 2017-02-05 23:59:09
How's your experience?
dramforever 2017-02-05 23:59:19
did you try to use it somewhere?
dramforever 2017-02-05 23:59:22
how it went
lyxia 2017-02-06 00:00:15
Unfortunately I haven't had the opportunity to use it. I just meant that it's a cool idea.
dramforever 2017-02-06 00:01:44
You did see it lacks support of many constucts right
lyxia 2017-02-06 00:03:04
Not before you just mentionned it.
dramforever 2017-02-06 00:05:04
:(
lyxia 2017-02-06 00:15:07
I think using >>= rather than join would make it easier to scale to other constructs.
lyxia 2017-02-06 00:16:21
(case (~! x) of ...) becomes (join (fmap (\x' -> case x' of ...) x)), i.e., (x >>= \x' -> case x' of ...)
lyxia 2017-02-06 00:18:40
dramforever: would that not work?
thatguy 2017-02-06 00:25:03
can anyone tell me some class for which one can instanciate a functor but not a applicative?
thatguy 2017-02-06 00:25:33
I find it hard to imagine since all the stuff I did functors for in the tutorials I can imagine easily how I would to an applicative
phadej 2017-02-06 00:25:45
thatguy: http://hackage.haskell.org/package/pointed-5/docs/Data-Pointed.html
phadej 2017-02-06 00:26:07
the lot discussed class
dramforever 2017-02-06 00:26:35
lyxia: Are you still there?
lyxia 2017-02-06 00:26:40
yeah
dramforever 2017-02-06 00:26:41
Sorry I was away
lyxia 2017-02-06 00:26:52
np
dramforever 2017-02-06 00:27:06
Because I would really like it if I could use fmap or <*>
dramforever 2017-02-06 00:27:35
like, say I have: case (~! getLine) of "randompassword123" -> Pass; _ -> NoPass
dramforever 2017-02-06 00:27:48
I don't want to use >>= here, because a fmap will do
lyxia 2017-02-06 00:28:03
Oh I see.
dramforever 2017-02-06 00:28:06
I think I really need some more 'indirect' techniques here
dramforever 2017-02-06 00:28:25
like converting to ANF or something, I don't know, I've never taken a compiler course
lyxia 2017-02-06 00:29:04
That makes sense. So in a case statement you need to look inside each alternative to see whether one is impure.
dramforever 2017-02-06 00:29:42
Yeah, like that
mniip 2017-02-06 00:30:14
1486380303 [14:25:03] can anyone tell me some class for which one can instanciate a functor but not a applicative?
dramforever 2017-02-06 00:30:27
but code has to be principled, it takes steps from examples to code
mniip 2017-02-06 00:30:27
(e, )
mniip 2017-02-06 00:30:27
for arbitrary e
thatguy 2017-02-06 00:30:55
phadej, thanks
mniip 2017-02-06 00:30:58
Const e, for arbitrary e, for the same reason
mniip 2017-02-06 00:31:15
Pair
thatguy 2017-02-06 00:32:55
mniip, thank you too
Taneb 2017-02-06 00:34:13
mniip, Pair can be an applicative, with similar semantics to ((->) Bool)
mniip 2017-02-06 00:34:22
hmm
mniip 2017-02-06 00:34:25
yeah perhaps
c_wraith 2017-02-06 00:34:28
Or a 2-element ziplist
mniip 2017-02-06 00:34:42
StateT s ZipList
Taneb 2017-02-06 00:34:44
pure x = Pair x x; Pair f g <*> Pair x y = Pair (f x) (g y)
mniip 2017-02-06 00:34:54
for a more contrived example
Taneb 2017-02-06 00:34:55
Pair can even be a Monad
c_wraith 2017-02-06 00:34:58
For an example of something that doesn't work as an applicative for different reasons, there's Coyoneda
thatguy 2017-02-06 00:35:02
in the CIS 194 tutorial it says you should implement: replicateA :: Applicative f => Int -> (f a) -> (f [a]) ... isn't Functor f enough here?
thatguy 2017-02-06 00:35:19
I would implement it as replicateA n fa = replicate n <$> fa and that is ok for functors
mniip 2017-02-06 00:35:33
thatguy, it is indeed
Taneb 2017-02-06 00:35:34
A variant of Void that takes a type paramater, ie. data VoidF a
c_wraith 2017-02-06 00:36:02
thatguy: that's a different operation
c_wraith 2017-02-06 00:36:32
thatguy: consider replicateA 4 (putStrLn "hello")
dramforever 2017-02-06 00:36:33
lyxia: You know what, I think I'm droppng that wish
mniip 2017-02-06 00:36:42
StateT s ZipList is a sad observation though
c_wraith 2017-02-06 00:37:11
thatguy: it should result in an action that outputs hello 4 times
c_wraith 2017-02-06 00:37:20
thatguy: your example would only output it once.
dramforever 2017-02-06 00:37:58
thatguy: the type is okay, but the behaviour is wrong
c_wraith 2017-02-06 00:38:14
thatguy: getting the correct behavior does require Applicative
thatguy 2017-02-06 00:38:17
c_wraith, can you give me an example of a functor where mine works wrong without IO?
thatguy 2017-02-06 00:38:29
I have to admit I didn't wrap my head around IO yet
c_wraith 2017-02-06 00:38:37
thatguy: sure. replicateA 4 (modify (+1))
thatguy 2017-02-06 00:39:05
ok thanks everyone I will take another look now
mniip 2017-02-06 00:39:12
replicateA 4 [False, True]
dramforever 2017-02-06 00:39:36
thatguy: 'replicateA n f' means 'do f, n times, gather the results'
mniip 2017-02-06 00:41:13
:t (sequenceA .) . replicate
lambdabot 2017-02-06 00:41:15
Applicative f => Int -> f a -> f [a]
lyxia 2017-02-06 00:41:35
dramforever: the wish of having principled code?
mniip 2017-02-06 00:41:44
:t ((sequenceA .) . replicate) 3 [False, True]
lambdabot 2017-02-06 00:41:46
[[Bool]]
mniip 2017-02-06 00:41:52
> (sequenceA .) . replicate
lambdabot 2017-02-06 00:41:54
error:
lambdabot 2017-02-06 00:41:54
• No instance for (Typeable f0)
lambdabot 2017-02-06 00:41:54
arising from a use of 'show_M543442908694248727111950'
mniip 2017-02-06 00:41:55
ugh
mniip 2017-02-06 00:42:05
messed up :s
mniip 2017-02-06 00:42:14
> ((sequenceA .) . replicate) 3 [False, True]
lambdabot 2017-02-06 00:42:16
[[False,False,False],[False,False,True],[False,True,False],[False,True,True]...
mniip 2017-02-06 00:42:29
compared with your solution,
mniip 2017-02-06 00:42:36
> (fmap . replicate) 3 [False, True]
lambdabot 2017-02-06 00:42:38
[[False,False,False],[True,True,True]]
dramforever 2017-02-06 00:43:42
lyxia: no, I mean the applicative/functor part
dramforever 2017-02-06 00:43:55
the functior part, just throw it away
dramforever 2017-02-06 00:44:04
and I'll do this for applicative https://ghc.haskell.org/trac/ghc/wiki/ApplicativeDo
dramforever 2017-02-06 00:44:15
s/functior/functor
dramforever 2017-02-06 00:44:36
I'll just emit do-notation and let the mighty GHC devs handle it
dramforever 2017-02-06 00:44:48
no point wasting my life on that