Search Haskell Channel Logs

Friday, January 27, 2017

#haskell channel featuring davean, Tuplanolla, clmg, lambdabot, eschnett, mniip,

Tuplanolla 2017-01-27 09:45:22
I wish it could calculate the width of multiline strings correctly.
zennist 2017-01-27 09:45:41
monochrom: what is the X product?
zennist 2017-01-27 09:45:44
link?
clmg 2017-01-27 09:45:58
Tuplanolla: you're using vty and brick? Don't they occupy a similar space functionality-wise?
Tuplanolla 2017-01-27 09:46:18
Brick is a Gloss-like layer on top of Vty, clmg.
Tuplanolla 2017-01-27 09:46:34
It has event handlers and layout managers and stuff.
clmg 2017-01-27 09:46:52
Tuplanolla: wow thanks I've been missing out.
Tuplanolla 2017-01-27 09:47:26
Still can't position that cursor.
zennist 2017-01-27 09:47:47
btw I found :.: :*: looks nicer..? say you have three things you want to compose together; then infix looks better isn't it?
zennist 2017-01-27 09:48:02
but i don't think i ever see people using these constructors
ph88 2017-01-27 09:48:34
this code has quite a few nested do-blocks .. how could i rewrite it to make it less verbose? https://paste.fedoraproject.org/537866/85550073/
ph88 2017-01-27 09:59:09
@pl data Foo = F String ; do (F x) <- F "foo"; return x
lambdabot 2017-01-27 09:59:09
(line 1, column 21):
lambdabot 2017-01-27 09:59:09
unexpected ';'
lambdabot 2017-01-27 09:59:10
expecting variable, "(", operator or end of input
ph88 2017-01-27 09:59:50
can i define some data with lamdabot ?
mniip 2017-01-27 10:03:03
ph88, yes, but not for @pl
ph88 2017-01-27 10:03:25
i'm using a do-block for this everytime
ph88 2017-01-27 10:17:45
is there a do-block equivalent of <*> ?
Rembane 2017-01-27 10:18:26
ph88: (x,y) <- ... ; f x y
Rembane 2017-01-27 10:18:42
ph88: Well, sometimes at least.
eschnett 2017-01-27 10:25:01
ph88: you are writing "return …" in your do statements. you don't need to end with a "return"; you can just write the respective expression instead, as in "do result <- calc; return result" becomes "do calc"
ph88 2017-01-27 10:25:26
ooh
ph88 2017-01-27 10:28:10
i have a whole bunch of ugly looking code like this https://paste.fedoraproject.org/537874/55247614/
ph88 2017-01-27 10:28:48
so in case of line 27 i can ommit the return ?
davean 2017-01-27 10:29:20
ph88: of course
davean 2017-01-27 10:29:31
ph88: what do you tihnk the return is doing there?
davean 2017-01-27 10:29:43
Its taking a thing, and making it back into exactly the thing it was
ph88 2017-01-27 10:29:53
i always use return
davean 2017-01-27 10:30:04
If you like to, do it, it doesn't actually do anything
davean 2017-01-27 10:30:28
I mean, what it does is puts some value into the monad
davean 2017-01-27 10:30:36
but you just got that value *out* of the monad
davean 2017-01-27 10:30:40
isj
davean 2017-01-27 10:30:42
*ish
davean 2017-01-27 10:32:13
ph88: maybe I can make it more clear
davean 2017-01-27 10:32:19
ph88: do you know how to desugar do notation?
ph88 2017-01-27 10:32:22
ya most of the time it's useful i think, for example on line 21 i need to make a tuple
ph88 2017-01-27 10:32:47
yes i can use >>= but i seldomly use >>=
davean 2017-01-27 10:33:01
Sure, but conceptually lets look at what we have in the actual function calls
davean 2017-01-27 10:33:18
we have some "m a" (the right side of the <- on ike 23)
davean 2017-01-27 10:33:23
and we're passing it to return
davean 2017-01-27 10:33:27
ma >>= return
davean 2017-01-27 10:33:38
so consider the types
davean 2017-01-27 10:33:52
(>>=) :: Monad m => m a -> (a -> m b) -> m b
davean 2017-01-27 10:34:04
and return :: Monad m => a -> m a
davean 2017-01-27 10:34:37
so (>>= return) becomes "m a -> m a"
ph88 2017-01-27 10:34:46
ye
davean 2017-01-27 10:34:48
That looks a lot like 'id' doesn't it?
ph88 2017-01-27 10:34:54
ye
davean 2017-01-27 10:35:04
we've given (>>= return) absolutely no ability to DO anything with m a
davean 2017-01-27 10:35:09
it just knows its a monad, thats not enough
ph88 2017-01-27 10:35:50
in case you want to combine a few things it becomes something like \x y -> return (x, y) ?
davean 2017-01-27 10:35:58
yep, basicly
davean 2017-01-27 10:36:04
YOu've got the idea
ph88 2017-01-27 10:36:16
yes i get the very basics of it
ph88 2017-01-27 10:36:32
i just know just enough syntax to make it compile (most of the time)
ph88 2017-01-27 10:37:07
there are still plenty of things i don't know ... for example i tried to move (n get) <*> into etwo and emore but that didn't work out
davean 2017-01-27 10:37:10
m a >>= (\a -> m b >>= (\b -> return (a, b))
davean 2017-01-27 10:37:14
to be explicite
davean 2017-01-27 10:37:25
but you don't need to think about it like that conceptually to understand how it works
davean 2017-01-27 10:38:17
Ah, I see why that wouldn't have worked - the point of <*> is you're filling in values to the function "And" or "Or" or whatnot
davean 2017-01-27 10:38:31
you'd need curry/uncurry
davean 2017-01-27 10:38:36
which isn't really what you want at all
ph88 2017-01-27 10:38:45
eh ok
davean 2017-01-27 10:38:48
what you COULD do is pass "And" and "Or" into etwo
ph88 2017-01-27 10:39:04
aaah right
ph88 2017-01-27 10:39:25
yeah i got stuck there everytime that i need to return a bunch of values, but of course i can only return 1 value with return
davean 2017-01-27 10:39:38
while you can do it the other way like you tried to initially, it doesn't make the code any prettier
ph88 2017-01-27 10:39:49
so there is no way i can use do-notation and return to give a few values to a data constructor ?
ph88 2017-01-27 10:39:58
ok ok
ph88 2017-01-27 10:40:39
i thought since there were so many parallels between applicative and monad that <*> must have a monad equivalent and also a do-notation
davean 2017-01-27 10:40:55
I mean, thats not your problem here
davean 2017-01-27 10:40:59
<*> works in monads
davean 2017-01-27 10:41:05
*must* work in monads
ph88 2017-01-27 10:41:22
only on the right side of the <- though ?
davean 2017-01-27 10:41:31
no
davean 2017-01-27 10:41:56
I don't think you understand how <$> ... <*> is working
davean 2017-01-27 10:42:18
You can't take the right side of that, the right side isn't really a thing
ph88 2017-01-27 10:42:20
not really .. but i still use them all the time succesfully
ph88 2017-01-27 10:42:29
tbh i'm not sure how i'm even writing haskell but it works o_O
davean 2017-01-27 10:42:36
Yah, they're not hard, but you can't section the expression like you're trying to
davean 2017-01-27 10:42:45
haskell isn't really that hard :)
ph88 2017-01-27 10:43:19
i just know that when i'm using <$> and then i want a few more things i should put a few <*> after that :P
davean 2017-01-27 10:43:45
I could explain it, but I'm not sure how useful explaining it would be ATM for you
ph88 2017-01-27 10:44:08
it's ok
ph88 2017-01-27 10:44:25
at least i have one suggestion: put the data constructor as argument to the function
ph88 2017-01-27 10:44:31
i don't do that a lot actually
ph88 2017-01-27 10:44:51
what would be the type of a data constructor though ?
davean 2017-01-27 10:44:58
Its just a function
davean 2017-01-27 10:45:06
data constructors are just functions