Search Haskell Channel Logs

Thursday, February 9, 2017

#haskell channel featuring glguy, jchia, Squarism, Koterpillar, lambdabot, ryantm____, and 11 others.

dhalgren 2017-02-09 16:47:41
and thx roboguy` ; should've recognised it
lpaste_ 2017-02-09 16:59:27
qmm pasted "parse error, missing something..." at http://lpaste.net/352297
Koterpillar 2017-02-09 17:02:13
qmm: try moving let to the right of ->
Koterpillar 2017-02-09 17:02:28
qmm: also, it's not in a do block, so it must be "let ... in ..."
Koterpillar 2017-02-09 17:02:34
oh wait
Koterpillar 2017-02-09 17:02:38
data is a keyword
qmm 2017-02-09 17:05:27
https://wiki.haskell.org/Keywords
qmm 2017-02-09 17:05:30
thanks Koterpillar
qmm 2017-02-09 17:05:46
and on that note :)
Squarism 2017-02-09 17:12:09
anyone vetted in scala? I wonder how i write : Maybe $ anExpression
Squarism 2017-02-09 17:12:19
in scala wo using (..)
Squarism 2017-02-09 17:12:35
Some expr
geekosaur 2017-02-09 17:13:18
why would you be asking about scala in here?
geekosaur 2017-02-09 17:14:00
(I see one person in here who I know has scala experience... and his opinion is "avoid")
EvanR 2017-02-09 17:14:28
edk
EvanR 2017-02-09 17:15:01
Squarism: #scalaz
monochrom 2017-02-09 17:15:25
Perhaps because scala people wouldn't know what "Maybe $ anExpression" means.
aarvar 2017-02-09 17:15:43
Squarism: `foo.some` ?
aarvar 2017-02-09 17:15:56
and I'm guessing you meant Just, not Maybe
monochrom 2017-02-09 17:15:57
I for one is in #haskell and couldn't answer "how do you write in Haskell?"
Squarism 2017-02-09 17:16:14
sorry
Squarism 2017-02-09 17:16:17
got desperate here
Squarism 2017-02-09 17:16:22
need to get home from work
Axman6 2017-02-09 17:16:39
do you mean Just $ anExpression??
Axman6 2017-02-09 17:16:44
s/??/?
dibblego 2017-02-09 17:16:56
Axman6 ❤ scala
EvanR 2017-02-09 17:17:13
while leaving the building you are confronted by a kung-fu master who refuses to let you pass without translating a snippet of haskell into scala
aarvar 2017-02-09 17:17:18
dibblego: everyone ❤ scala
Squarism 2017-02-09 17:17:59
Axman6, yes.. but now ive dropped it.
monochrom 2017-02-09 17:19:04
You can get past the kung-fu master by asking them "what would you answer if you were asked which way is the way out?"
monochrom 2017-02-09 17:19:15
@quote monochrom sentinel
lambdabot 2017-02-09 17:19:15
No quotes match.
thepreacher 2017-02-09 17:19:17
Working through haskellbook and am stuck of the following exercise. Given a :: (a -> c) -> a -> a define a function that will type check. My solution so far is myFunc aToc a = (aToc a). But I think its wrong because the signature for that is myFunc :: (a -> c) -> a -> c.
monochrom 2017-02-09 17:19:38
@quote monochrom angel
lambdabot 2017-02-09 17:19:38
monochrom says: at a crossroad you meet an angel (always tells the truth) or demon (always lies). the crossroad gives you two choices of roads, one to heaven, one to hell, and only the angel or
lambdabot 2017-02-09 17:19:38
demon knows which is which. if you ask "how would you answer if I asked 'what is a monad?'", what will happen?
monochrom 2017-02-09 17:19:57
That may also work :)
jchia 2017-02-09 17:20:00
I'm making binary getter & putter for some nested product type. The serialization result is fixed-length, so I want to use 'isolate' in my getter. However, hand-calculating the number of bytes expected is quite tedious. Is there a way to get the number of bytes automatically or semi-automatically in a less error-prone way? I suppose for each type that needs to be serialized/deserialized, I can define a compile-time value for the "number of bytes needed", and
vandino 2017-02-09 17:20:26
hello
monochrom 2017-02-09 17:20:28
So many "a"s
glguy 2017-02-09 17:20:32
thepreacher: you're right, your given solution has the wrong type
EvanR 2017-02-09 17:21:05
jchia: theres sizeOf
monochrom 2017-02-09 17:21:12
I'm wondering if you should care about the parameter at all.
monochrom 2017-02-09 17:21:27
err, I mean the first parameter.
glguy 2017-02-09 17:21:32
you've got values with types a, and a->c. you need a value with type a, what do you do?
jchia 2017-02-09 17:21:45
EvanR: sizeOf from Foreign.Storable? How do I bridge Foreign.Storable and Data.Binary?
glguy 2017-02-09 17:22:07
it's not necessary to care about all the parameters
EvanR 2017-02-09 17:22:56
jchia: er uh... you could replicate that scheme, define a class Sized and everything involved has an instance which calculates your binary size from whatever it consists of (which are also sized)
monochrom 2017-02-09 17:23:35
jchia: There is no need to bridge. Write Storable instances for your types. Then just call sizeOf when you serialize. It doesn't even have to be Storable, it can be your own class of your invention.
jchia 2017-02-09 17:23:52
is Storable derivable?
EvanR 2017-02-09 17:24:08
i have seen Binary be derivable
EvanR 2017-02-09 17:24:11
through TH
monochrom 2017-02-09 17:24:16
No, but it is composable.
monochrom 2017-02-09 17:24:26
err, compositional.
thepreacher 2017-02-09 17:25:24
glguy: I thought of myFunc _ a = a which from GHCi gives a type signature of myFunc :: t1 -> t -> t but t1 doesn't capture the idea of being a function.
monochrom 2017-02-09 17:25:36
I mean this. If you have "data X = ..." and you know how to write it's sizeOf, then when you have "data Y = Ctor X X X", then you simply write Y's sizeOf (Ctor x _ _) = 3 * sizeOf x
jchia 2017-02-09 17:25:42
monochrome: I think using Storable involves IO, so it's impure
monochrom 2017-02-09 17:25:57
So you still have to handwrite something but it is tractable.
EvanR 2017-02-09 17:26:04
sizeOf doesn't involve IO
glguy 2017-02-09 17:26:10
I don't know what you were thinking the idea of being a function was, but that's the right solution
monochrom 2017-02-09 17:26:44
Again, you can always make your own class.
jchia 2017-02-09 17:26:45
EvanR: But since I'm using Storable, shouldn't I use the other functions to do the get and put? Or do I use Storable just for the sizeOf?
EvanR 2017-02-09 17:27:00
i would make my own class
monochrom 2017-02-09 17:27:07
And while you invent your own class, you can bring in Proxy so you don't have to use undefined.
monochrom 2017-02-09 17:27:28
class MySize t where size :: proxy t -> Int
thepreacher 2017-02-09 17:27:37
glguy: Hmm thanks.
EvanR 2017-02-09 17:27:42
and the only reason to use a class here is to use the same word "size" at each stage
glguy 2017-02-09 17:27:46
don't put Proxy in the class though, proxy is better for that
monochrom 2017-02-09 17:27:52
yeah
EvanR 2017-02-09 17:28:26
if everything were in its own module you could also do Foo.size Bar.size, etc, and no proxies would be harmed in the making of this calculation
monochrom 2017-02-09 17:28:40
And so it doesn't even have to be Proxy. It can be "size ([] :: [Y])"
jchia 2017-02-09 17:28:51
monochrome: What about the 'compositional' part?
monochrom 2017-02-09 17:29:08
You saw my sentence starting with "I mean this"?
jchia 2017-02-09 17:29:26
e.g. if I have data Foo = Foo {bar :: Bar, bar :: Baz}, how do I define the size of Foo?
EvanR 2017-02-09 17:29:55
sizeOf bar + sizeOf baz ?
monochrom 2017-02-09 17:29:56
size of Foo = size of Bar + size of Baz, no?
jchia 2017-02-09 17:30:43
monochrom: Yes, but it's still boilerplate. i already defined the constituents of Foo and then I still have to define the size in the same way.
monochrom 2017-02-09 17:30:58
What we're telling you now, which can be done in an hour, can be saved by 4 days of learning Template Haskell, GHC.Generics, and Data.Generics, and then arguing with yourself which way to go.
glguy 2017-02-09 17:31:15
it's not even necessary to use isolate
glguy 2017-02-09 17:31:29
so we could solve this exercise by not solving it
jchia 2017-02-09 17:31:55
glguy: If I use isolate, I'll find out early that the input is too short
monochrom 2017-02-09 17:32:00
Sorry, what is isolate again?
jchia 2017-02-09 17:32:30
'reserve' a number of bytes. if we end up consuming less or trying to consume more, the get fails.
glguy 2017-02-09 17:35:14
what kind of expensive computation are you doing during deserialization that there is an "early"?
jchia 2017-02-09 17:35:15
my top-level product type is not very deep. maybe i'll just calculate the size by hand.
jchia 2017-02-09 17:35:58
glguy: It's not about calculation. it's just about trying to follow the principle of failing early
jchia 2017-02-09 17:37:13
glguy: But it's just a general principle, I really need to isolate.
jchia 2017-02-09 17:37:19
i mean i don't need
monochrom 2017-02-09 17:37:37
Sure. If you have written 1MB and then find that the length is wrong after all, I can agree that it's too late.
monochrom 2017-02-09 17:37:57
But until you have written 64KB or something, I say it is still early enough.
glguy 2017-02-09 17:38:15
this is reading not writing
monochrom 2017-02-09 17:38:24
Reason being buffer size etc etc.
jchia 2017-02-09 17:38:43
I'm converting from one format to another, so it's preferable to output less garbage when the input is garbage
jchia 2017-02-09 17:39:11
but it's not essential, maybe i don't need it
jchia 2017-02-09 17:39:18
if it takes so much engineering effort
monochrom 2017-02-09 17:40:51
Bear in mind that even lazy bytestring is in 64KB blocks
jchia 2017-02-09 17:42:09
Although I haven't analyzed the laziness, I think I'll fully evaluate the entire top-level product type before I output anything for it, so here outputting less garbage here is probably moot, so I think glguy is right.
ryantm____ 2017-02-09 17:43:21
I was playing with the example code in https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#generalised-algebraic-data-types-gadts and I was trying to derive Show for Term, but it cannot derive show for Pair: https://gist.github.com/ryantm/2d548185fc81c98775f0d591343b26e5 Is there some way to modify it so it can derive Show for
ryantm____ 2017-02-09 17:43:21
Pair?
ryantm____ 2017-02-09 17:44:16
I tried using type equality in the definition of Pair like: Pair :: a ~ b => Term a -> Term b -> Term (a,b) but that didn't work