Search Haskell Channel Logs

Tuesday, January 31, 2017

#haskell channel featuring roxxik, Ferdirand, laz, ocharles, exferenceBot, merijn, and 11 others.

quchen 2017-01-30 22:50:38
antalsz: I'm not sure. Mapping is typically something that can be stream-fused away so it can be done on pure vectors without overhead compared to the mutable version.
quchen 2017-01-30 22:50:51
So I wouldn't be surprised if the library didn't have it.
antalsz 2017-01-30 22:51:30
quchen: Fair enough. Do you have any good resources for trying to understand when fusion will fire?
quchen 2017-01-30 22:51:47
antalsz: When the documentation says »subject to fusion« :-)
antalsz 2017-01-30 22:52:00
quchen: :-)
quchen 2017-01-30 22:52:12
Eeeek okay Vector does not say that
quchen 2017-01-30 22:52:12
(Text does)
antalsz 2017-01-30 22:52:42
But, for instance, avg v = V.foldr (+) 0 v / V.foldr (\_ n -> 1 + n) 0 v won't fuse, I presume
antalsz 2017-01-30 22:52:56
because you're foldring twice
quchen 2017-01-30 22:53:13
In that case: look at the Core output. But before that, make sure you care enough about the performance.
quchen 2017-01-30 22:53:50
It's perfectly fine to implement your own average function in ST, but you're venturing into unsafe territory, so it requires care.
quchen 2017-01-30 22:54:05
For »average«, you can solve the problem with a single fold.
antalsz 2017-01-30 22:54:10
quchen: Indeed, root of all evil and all that
antalsz 2017-01-30 22:54:40
also, V.foldr (+) 0 v / V.length v, since length doesn't need a fold – it was just the first not-totally-silly example I could think of
antalsz 2017-01-30 22:55:18
anyway, thanks for the pointers; I'll see whether mutable or immutable feels like the better model
quchen 2017-01-30 22:55:31
The standard deviation of a vector needs length, sum and sum-of-squares. That one can't be implemented that easily.
quchen 2017-01-30 22:56:02
But even this case can be done using a single fold, because you can consume the input element-wise. :-)
orion 2017-01-30 22:56:04
What functions should I consider if I want to write an application which can load/execute other haskell shared libraries at runtime, given some "Plugin" typeclass?
quchen 2017-01-30 22:57:06
antalsz: But the general answer to »did fusion work« is looking at the GHC debug output of what rules did fire, or studying the core output.
quchen 2017-01-30 22:57:56
If you see stream/unstream a lot in core, chances are fusion did not fire. So that gives you a »grep -n« level estimate :-)
antalsz 2017-01-30 22:57:56
quchen: ooh, rules that fired seems like a nice choice, as does stream/unstream!
quchen 2017-01-30 22:58:00
I don't know the GHC flag that prints all firing rules, but there is one.
quchen 2017-01-30 22:58:16
Gotta go, good luck! @tell me or ask others around here if you want to know more :-)
geekosaur 2017-01-30 23:00:57
-ddump-rule-firings and maybe -ddump-rule-rewrites for gory details
roxxik 2017-01-30 23:06:10
is it possible for the exf bot to join #haskell.de?
roxxik 2017-01-30 23:06:14
:exf (a,b) -> a
ph88^ 2017-01-30 23:06:19
what would be the idiomatic haskell way to write this piece of IO code ? https://paste.fedoraproject.org/541401/14858571/
exferenceBot 2017-01-30 23:06:46
could not find expression
roxxik 2017-01-30 23:06:46
yesterday it worked :(
roxxik 2017-01-30 23:07:00
:exf a -> a
exferenceBot 2017-01-30 23:07:00
parse error: more than one input
roxxik 2017-01-30 23:07:12
:exf a -> a -> b
exferenceBot 2017-01-30 23:07:12
parse error: more than one input
roxxik 2017-01-30 23:07:18
:exf f :: a -> a -> b
geekosaur 2017-01-30 23:07:19
ph88, `if` isd an expression, not a statement, even in do syntax
exferenceBot 2017-01-30 23:07:19
could not parse input type: ParseFailed (SrcLoc "inputtype.hs" 1 3) "Parse error: ::"
ph88^ 2017-01-30 23:07:23
what's this bot ?
roxxik 2017-01-30 23:07:32
it generates code from types
geekosaur 2017-01-30 23:07:38
and you have to use another `do` in the `else`
roxxik 2017-01-30 23:08:00
i had it generate the bind function of state (minus newtype conversions)
miladz89 2017-01-30 23:08:11
any snappers here ? how can I send a synchronous (or any request) request using snap ?
geekosaur 2017-01-30 23:08:46
ph88^, exferenceBot is djinn on steroids, https://github.com/lspitzner/exference
roxxik 2017-01-30 23:09:00
:exf (s -> (a,s)) -> (a -> s -> (b,s)) -> s -> (b,s)
exferenceBot 2017-01-30 23:09:01
\ f1 f2 c -> let ((,) g h) = f1 c in f2 g h
ph88^ 2017-01-30 23:10:23
cool bot :P
ph88^ 2017-01-30 23:10:30
now we can all go home and let exferenceBot do the work
roxxik 2017-01-30 23:10:45
:exf ((a -> r) -> r) -> (a -> ((b -> r) -> r)) -> ((b -> r) -> r)
exferenceBot 2017-01-30 23:10:46
\ f1 f2 f3 -> f1 (\ f -> f2 f f3)
ph88^ 2017-01-30 23:10:58
roxxik, maybe you can query the bot directly
roxxik 2017-01-30 23:11:19
i wanted to show off something, and don't wanted to spam the #haskell channel ;)
roxxik 2017-01-30 23:11:30
but there is #exference, i'll use that one next time
ph88^ 2017-01-30 23:12:53
it's your bot ?
geekosaur 2017-01-30 23:13:32
I think hexagoxel maintains it currently?
ph88^ 2017-01-30 23:14:05
geekosaur, is it possible to skip the pathExist <- doesPathExist path part and use doesPathExist path directly in the if clause ?
geekosaur 2017-01-30 23:14:14
ph88^, no
geekosaur 2017-01-30 23:14:22
an IO Bool is not a Bool
jophish 2017-01-30 23:16:30
ph88^: often in these cases I do something like: getArgs >>= \case {[] -> putStrLn "no args"; _ -> putStrLn "some args"}
jophish 2017-01-30 23:17:28
so you could do: `doesPathExist >>= bool (doesn't exist) (does exist)` or `doesPathExist >>= \case {True -> ...; False -> ...}`
roxxik 2017-01-30 23:17:30
this i where i use \case most often too
ph88^ 2017-01-30 23:28:18
anyone know how i can fix this problem with the types ? https://paste.fedoraproject.org/541411/14858584/
geekosaur 2017-01-30 23:29:02
do you ever plan to learn Haskell, or just rely on #haskell to fix things for you?
BernhardPosselt 2017-01-30 23:29:47
monad transformers are about combining monads, correct?
ph88^ 2017-01-30 23:30:09
well i already learned a lot i think
geekosaur 2017-01-30 23:30:11
mm, actually, that ... ph88^, what version of ghc are you using?
ph88^ 2017-01-30 23:30:24
geekosaur, you want to see my biggest program? it shows what i already understand
geekosaur 2017-01-30 23:30:33
you haven't learned how do notation works yet, still, per your last but one paste
ph88^ 2017-01-30 23:30:42
true
BernhardPosselt 2017-01-30 23:30:49
how extensive is the built in monad transformer lib?
BernhardPosselt 2017-01-30 23:31:03
does it cover all built in monads?
ph88^ 2017-01-30 23:31:04
geekosaur, ghc 8.0.1
Ferdirand 2017-01-30 23:31:05
Couldn't match type '[Char]' with 'String'
Ferdirand 2017-01-30 23:31:07
what ?
geekosaur 2017-01-30 23:32:09
... wat. I was thinking this was an 8.2 prerelease since they've been talking about making FilePath abstract... but
ph88^ 2017-01-30 23:32:19
maybe i can use a type conversion function [Char] -> String
geekosaur 2017-01-30 23:32:34
did you redefine String?
jophish 2017-01-30 23:32:41
https://hackage.haskell.org/package/foundation-0.0.3/docs/Foundation.html#t:String geekosaur
ph88^ 2017-01-30 23:32:52
foundation package might have redefined string, otherwise all of my source code is in that paste
jophish 2017-01-30 23:33:01
ph88^: it's due to the use of Foundation, that redefines 'String'
geekosaur 2017-01-30 23:33:21
oh brother
ph88^ 2017-01-30 23:33:38
yeah i made an issue about it, but i thought maybe if i can figure out how to fix it i can contribute something back or something
jophish 2017-01-30 23:34:03
ph88^: you can use 'toList' to convert to [Char] I think
roxxik 2017-01-30 23:34:03
Foundation: newtype String = String (UArray Word8)
roxxik 2017-01-30 23:34:20
but the constructor is not exported
merijn 2017-01-30 23:34:40
ph88^: Obligatory "doesPathExist is a TOCTOU-race" warning
ph88^ 2017-01-30 23:34:51
ok ill search for some conversion function, thx guys
jophish 2017-01-30 23:35:28
ph88^: toList
jophish 2017-01-30 23:35:44
and presumably fromList
ph88^ 2017-01-30 23:35:47
merijn, what are you saying? should i check time and build in a warning ?
geekosaur 2017-01-30 23:36:10
you should let the operation using the file fail and check forthat, not test it beforehand
jophish 2017-01-30 23:36:19
ph88^: you might check that it exists, and between that check and you using the file it could have been removed
merijn 2017-01-30 23:36:45
ph88^: TOCTOU = Time-of-check, Time-of-use
geekosaur 2017-01-30 23:36:46
or swapped with a different one so any tests you did beforehand are against the wrong file
merijn 2017-01-30 23:36:55
ph88^: It's similar to "doesFileExist" in that sense
miladz89 2017-01-30 23:37:11
any one who knows snap ?
ph88^ 2017-01-30 23:37:12
jophish, i solved it, with getCurrentDirectory >>= \x -> putStrLn (show x) documentation says it's slow, but it works nevertheless
merijn 2017-01-30 23:37:22
ph88^: What happens if you run "doesPathExist", it returns True and now someone deletes the path before you can actually run the action using the path
ph88^ 2017-01-30 23:39:00
so i should use openFile immediately and then start catching exception ?
merijn 2017-01-30 23:39:51
ph88^: Yeah, it's the only sane way
ph88^ 2017-01-30 23:40:18
ok i better read up on exception handling then, haven't looked into that yet ^^
roxxik 2017-01-30 23:40:41
try? anyone
roxxik 2017-01-30 23:40:43
:t try
lambdabot 2017-01-30 23:40:45
Exception e => IO a -> IO (Either e a)
ph88^ 2017-01-30 23:41:00
go for it geekosaur ! :D
jophish 2017-01-30 23:41:03
geekosaur: I'd use a package that supplied things like "readFileOrNothing :: FilePath -> IO (Maybe ByteString)" and friends
jophish 2017-01-30 23:41:19
I've implemented that quite a bit in my own code but never abstracted it out
ph88^ 2017-01-30 23:42:00
jophish, that might be a good suggestion for a new prelude, you mind if i copy paste that on github ?
geekosaur 2017-01-30 23:42:31
well, probably it'd be ExceptT
jophish 2017-01-30 23:42:40
ph88^: I'm not sure we need any more preludes :)
ocharles 2017-01-30 23:42:41
Any advice on whether one should use writeIORef or atomicWriteIORef?
noan 2017-01-30 23:42:42
Does mappen have a general name when abstracted away from haskell?
noan 2017-01-30 23:42:46
mappend*
merijn 2017-01-30 23:42:53
geekosaur: tbh, I just want to remove unchecked exceptions and make Haskell have checked exceptions
jophish 2017-01-30 23:43:00
geekosaur: sure
ph88^ 2017-01-30 23:43:02
jophish, :(
ocharles 2017-01-30 23:43:03
Assume usage in a concurrent environment
merijn 2017-01-30 23:43:33
ocharles: Is the IORef shared? What consistency model do you require?
ocharles 2017-01-30 23:43:54
yes, shared, it's a counter that web requests increment to log the total amount of requests served
roxxik 2017-01-30 23:43:56
merijn: do you mean all exeptions, or only the synchronous ones?
ocharles 2017-01-30 23:43:56
(for example)
merijn 2017-01-30 23:43:58
noan: Not really, mappend is common in algebra, but it doesn't really have a name
cocreature 2017-01-30 23:43:58
ocharles: in that case, I would use atomicWriteIORef unless it is a performance bottleneck. it's easier than having to figure out if writeIORef is really safe
merijn 2017-01-30 23:44:10
roxxik: I haven't decide yet
noan 2017-01-30 23:44:18
merijn, okay, I couldn't find anything on the wikipedia semigroup or monoid topics so I wasn't sure
ocharles 2017-01-30 23:44:20
That was my thinking. It's a shame, because writeIORef allocates 0 bytes, but atomicWriteIORef allocates 80
ocharles 2017-01-30 23:44:22
but not the end of the world
merijn 2017-01-30 23:44:28
cocreature: writeIORef is afe, it just might not have the consistency you want :p
merijn 2017-01-30 23:44:43
ocharles: What sort of consistency do you want?
ocharles 2017-01-30 23:44:46
incrementing the counter takes 120 bytes anyway, it's just "setting to a known value" that would have been allocation free
merijn 2017-01-30 23:44:47
and/or need
ocharles 2017-01-30 23:44:56
merijn: I don't know enough about consistencies to answer that question
laz 2017-01-30 23:45:08
noan: it can be called monoid product