vijay 2017-02-05 02:48:17
Hi, Can anybody explain (or point to a good resource) how do you identify what monads you need in your application. I read that "Monads are a remarkably elegant way for structuring programs in a flexible and extensible way".
ggVGc 2017-02-05 02:51:41
vijay: it's not about "what monads you need". It's more about "Is this computation monadic"
tfc 2017-02-05 02:52:18
vijay i am still no expert at this, but i wrote little example apps in order to understand the most typical monads. (state, reader, writer, etc.) and as soon as you understand how to use them, you will see automatically where you can profit from them.
halogenandtoast 2017-02-05 02:52:48
Is there any obvious way to use persistant to query on a range. For example, given a UTCTime I want a query that checks if a value is in the same day.
halogenandtoast 2017-02-05 02:53:18
I'm considering trying to use esqueleto instead, but I don't see an obvious way to do it there either.
michaelt 2017-02-05 02:54:40
sternmull: here is a little course of action. ghc -O2 -prof -rtsopts
sternmull 2017-02-05 02:54:49
Oh, i found the reason for all the allocations: By default the numbers are handled as Integer which need allocations because they are of variable size. When i force the numbers to Int then only a constant allocation remains (independent of the length of the list).
vijay 2017-02-05 02:54:50
I can use monads in my application. And I always figure out (later) that something could be a monad. And then refactor some code to make it Monadic. I thought there is a better way !
michaelt 2017-02-05 02:55:42
sternmull: sternmull ghc -O2 -prof -rtsopts foldl.hs ; fold +RTS -hc ; hp2ps fold; open fold.ps
michaelt 2017-02-05 02:58:13
sternmull do you have hp2ps I think it comes with ghc. I shouldn't have used ; above, it's just the sequence of things I typed beginning ghc -O2 -prof -rtsopts fold.hs
vijay 2017-02-05 02:58:27
ggVgc, tic: Comparing to my Java days, I feel what I am doing now is like to refactor code to come up with new object/class :)
sternmull 2017-02-05 02:59:25
michaelt: Yes i have hp2ps and your command works fine. What is -rtsopts? Can't find it in the ghc manual.
michaelt 2017-02-05 02:59:46
sternmull: the result of viewing blah.ps will show you the memory use over time. If you look at it, there is no comparison between foldl' and foldr
michaelt 2017-02-05 03:00:09
-rtsopts is needed to use +RTS -blah
michaelt 2017-02-05 03:00:19
I'm not sure of all the ins and outs of it
michaelt 2017-02-05 03:00:50
there were security reasons for making you request it explicitly in compiling
sternmull 2017-02-05 03:01:05
But "+RTS -p" woks without -rtsopts.
michaelt 2017-02-05 03:01:44
you compile with -prof -rtsopts or with -threaded -rtsopts , then you can do stuff like +RTS -hc or in the concurrency case, +RTS -N2 for cores etc etc
michaelt 2017-02-05 03:01:58
sternmull: yes that puzzled me, my information is incomplete
sternmull 2017-02-05 03:02:32
maybe -p is more primitive and does not need -rtsopts. After all it just prints a few resource counters.
michaelt 2017-02-05 03:02:35
maybe it's let through because -prof is obviously a development thing?
vijay 2017-02-05 03:02:38
ggVGc: Are you suggesting that I should be thinking about all computations in application and then see if any of them are Monadic in nature?
michaelt 2017-02-05 03:03:07
sternmull: total speculation.
sternmull 2017-02-05 03:03:14
yes :)
michaelt 2017-02-05 03:04:13
sternmull: I have been using -rtsopts in compiling when I propose to use +RTS ... when running, for so long I may be out of date
michaelt 2017-02-05 03:05:05
sternmull: with -threaded you might actually want to run an executable on some days with -N1 on others with -N16
michaelt 2017-02-05 03:08:50
sternmull: anyway, i hope that picture of how to get a .ps file was clear enough, though typed badly.
sternmull 2017-02-05 03:11:52
michaelt: Yes, that was helpful. But for now i have to learn more about effectively writing haskell code. Performance considerations can wait for later... or maybe never be an issue in practice.
michaelt 2017-02-05 03:23:55
sternmull: benchmarking with criterion is always good! It's a little fiddly sometimes.
Xnuk 2017-02-05 03:24:56
simendsjo: Here's my solution. hth https://gist.github.com/xnuk/0074ac3235ca471ee39c77eebf2dbf71
sternmull 2017-02-05 03:26:38
michaelt: It is good to know such tools exist. But at the moment i really should invest my time in getting used to haskell. And the project i evaluate it for is not really performance critical. It will spend 99.9% of its time with copying files, sending/receiving network streams and waiting for child processes.
michaelt 2017-02-05 03:29:01
sternmull: here's an example where i was helping an SO user for such problems, and we were using hs2ps http://stackoverflow.com/questions/41905139/reduce-memory-usage-of-a-haskell-program/41938047
thatguy 2017-02-05 03:29:29
I am getting no instance of Eq h, but I have no clue where I am comparing h to anything, can someone take a look? http://lpaste.net/352108
thatguy 2017-02-05 03:29:43
code is only ~5 lines
michaelt 2017-02-05 03:30:28
thatguy: the line `g str2 == Nothing ...`
michaelt 2017-02-05 03:30:43
thatguy: means g has to result in a thing that has an Eq instance
michaelt 2017-02-05 03:31:18
so that g str2 == x makes sense
thatguy 2017-02-05 03:31:19
but g is of type String -> Maybe (a, String)), i.e. g str is of type Maybe (a, String)
thatguy 2017-02-05 03:31:32
ahh and Maybe is not of Eq instance if a is not, right?
thatguy 2017-02-05 03:31:35
is that the problem?
michaelt 2017-02-05 03:31:40
right, but haw can i tell if two e Maybe (a, String) are the same
michaelt 2017-02-05 03:31:44
right
thatguy 2017-02-05 03:32:00
ah ok thanks :)
thatguy 2017-02-05 03:32:08
is there a way to just check if it is Nothing?
michaelt 2017-02-05 03:32:22
yes
sternmull 2017-02-05 03:32:54
michaelt: Thanks, bookmarking the link. Maybe it comes in handy later.
michaelt 2017-02-05 03:33:23
h (Just (fRes, str2)) = case g str2 of Nothing -> whatever; Just _ -> whateverelse
michaelt 2017-02-05 03:33:29
thatguy: ^^^
halogenandtoast 2017-02-05 03:33:50
I doubt anyone did, but if someone answered my question from 22:52 I had step away.
thatguy 2017-02-05 03:34:23
michaelt, does case do something else than compare?
halogenandtoast 2017-02-05 03:34:59
but now that I'm back, does anyone know how to do a between query with either persistent or esqueleto?
michaelt 2017-02-05 03:35:18
thatguy: well it just looks at the constructor the type as whole neednt support Eq
thatguy 2017-02-05 03:35:43
so its just another pattern match so to say?
michaelt 2017-02-05 03:35:45
thus e.g. Maybe (Int -> Int) can be inspect for Just or Nothing, but has no Eq instance
michaelt 2017-02-05 03:35:48
yeah
thatguy 2017-02-05 03:36:08
michaelt, ok, thanks for taking the time to help :)
halogenandtoast 2017-02-05 03:38:41
I suppose I can just use rawSql
michaelt 2017-02-05 03:40:56
halogenandtoast: you can check the feed here http://tunes.org/~nef/logs/haskell/ or http://ircbrowse.net/day/haskell/today/recent
michaelt 2017-02-05 03:41:01
halogenandtoast: for what it's worth
halogenandtoast 2017-02-05 03:41:35
michaelt: Thanks!
halogenandtoast 2017-02-05 03:41:51
should have read the top
michaelt 2017-02-05 03:42:16
oh I forget they mention it
halogenandtoast 2017-02-05 03:43:10
yeah, and lo and behold my question was not answered, as expected, but now I can be certain.