athan 2017-02-21 02:45:24
> do {x <- [1,2]; y <- [4,5]; let pair = (x,y) in pair}
pavonia 2017-02-21 02:45:28
Cooler: With Applicative all actions could be evaluated in parallel because they are independent of each other, imagine the results of all are combined at the end
lambdabot 2017-02-21 02:45:30
error:
lambdabot 2017-02-21 02:45:30
• Couldn't match type '(,) Integer' with '[]'
lambdabot 2017-02-21 02:45:30
Expected type: [b]
athan 2017-02-21 02:45:40
ermp
athan 2017-02-21 02:45:45
> do {x <- [1,2]; y <- [4,5]; pure $ let pair = (x,y) in pair}
lambdabot 2017-02-21 02:45:49
[(1,4),(1,5),(2,4),(2,5)]
yushyin 2017-02-21 02:46:01
> [let p = (x, y) in p | let y = 1, let x = 'a']
lambdabot 2017-02-21 02:46:07
[('a',1)]
pavonia 2017-02-21 02:46:09
Cooler: With Monad you can't (always) evaluate then in parallel, because one action could depend on the result of any other action
t4nk800 2017-02-21 02:46:23
if I have mutiple let expressions are they separated with commas : let a = 3+x, let b = a+3?
mauke 2017-02-21 02:46:34
yes
t4nk800 2017-02-21 02:46:41
thank you.
Cooler 2017-02-21 02:46:50
pavonia, well no when you chain using <*> each function does depend on the previous result
Cooler 2017-02-21 02:47:03
you can't run that in parallel
pavonia 2017-02-21 02:47:12
You can
Cooler 2017-02-21 02:47:27
> pure (+1) <*> (pure (*2) <*> pure 2 :: Maybe Int)
pavonia 2017-02-21 02:47:30
How does it depend on the previous one?
lambdabot 2017-02-21 02:47:31
Just 5
Cooler 2017-02-21 02:47:55
you have to run *2 on 2 first
mauke 2017-02-21 02:48:02
Cooler: you can run pure (+1), pure (*2), pure 2, all in parallel
Cooler 2017-02-21 02:48:03
then +1
Cooler 2017-02-21 02:48:23
mauke, what?
Cooler 2017-02-21 02:49:52
mauke, ok well that makes sense if its IO (+1)
Cooler 2017-02-21 02:50:46
but you still need to chain them in order when evaluating the expression
pavonia 2017-02-21 02:50:58
You have to distunguish between the evaluation of the actions and combining the results of these actions. The latter of course has so certan order because you are applying a function to various parameters
mbrock 2017-02-21 02:51:16
in ghci, can I somehow get a maximally polymorphic type of a top-level definition that has been monomorphized?
mbrock 2017-02-21 02:51:52
like, print the constraints that can be derived from the definition
pavonia 2017-02-21 02:51:55
Cooler: But with Monad you can't even evaluate an action itself without having evaluated the previous actions
mbrock 2017-02-21 02:52:38
ahh, I just disable the monomorphism restriction and there we go
pavonia 2017-02-21 02:52:57
Cooler: (>>=) takes an additional parameter which is the result of the previous action. You need this to even know how the second action looks like
Cooler 2017-02-21 02:53:40
pavonia, what do you mean another parameter?
Cooler 2017-02-21 02:53:51
hidden parameter?
pavonia 2017-02-21 02:53:51
:t (<*>)
lambdabot 2017-02-21 02:54:14
Applicative f => f (a -> b) -> f a -> f b
pavonia 2017-02-21 02:54:22
:t (>>=)
lambdabot 2017-02-21 02:54:24
Monad m => m a -> (a -> m b) -> m b
pavonia 2017-02-21 02:55:06
Cooler: I meant the 'a' in the second function
mauke 2017-02-21 02:55:19
do { c <- getChar; case c of { '-' -> getChar; '?' -> return 'A'; _ -> putchar c >> return c } -- can't do this with Applicative
mauke 2017-02-21 02:56:11
depending on the result of the first getChar, we either run a second getChar, do nothing, or run a putChar
Cooler 2017-02-21 02:58:13
well i think it would be a lot clearer to say the each structure is independent in case of functor or applicative
Cooler 2017-02-21 02:58:55
instead of saying computation because that makes it seem like your talking about (+1) $ (*2) 2
Cooler 2017-02-21 03:12:56
is this a valid Applicative? http://lpaste.net/352815
Cooler 2017-02-21 03:13:06
seems like it would fail composition
merijn 2017-02-21 03:13:41
Cooler: Hard to say without the definition of CountMe
Cooler 2017-02-21 03:13:43
or maybe not
Cooler 2017-02-21 03:14:18
data CountMe a = CountMe Integer a deriving (Eq, Show)
merijn 2017-02-21 03:14:19
Actually it isn't valid, because of your choice of pure :)
merijn 2017-02-21 03:14:29
'0' is not the identity for *
merijn 2017-02-21 03:14:38
But you could make a valid one
Cooler 2017-02-21 03:14:52
oh
Cooler 2017-02-21 03:14:54
right
Cooler 2017-02-21 03:15:01
"This'll pass as a valid Functor and Applicative, but it's not a valid Monad." they need to fix that
merijn 2017-02-21 03:15:04
Actually, you could make 2 (probably even more :p) valid ones
warbo 2017-02-21 03:15:24
hello, I'm feeding large lazy values into a hashing algorithm and want to know if it's running in constant space (forcing part of the value, updating the hash, recursing on the rest, garbage-collecting the forced part)
warbo 2017-02-21 03:15:44
I'd like to do thi programatically, rather than fiddling with GHC options from bash
warbo 2017-02-21 03:16:07
I've played with weigh, but it only seems to give me total allocation, rather than e.g. max residency
warbo 2017-02-21 03:16:13
is there a better tool for this?
merijn 2017-02-21 03:17:06
warbo: For finding out the memory usage of code?
warbo 2017-02-21 03:17:14
yes
Zemyla 2017-02-21 03:17:19
How are pinned byte arrays garbage collected?
merijn 2017-02-21 03:17:20
warbo: The sanest way is to build a profiling version
merijn 2017-02-21 03:17:41
warbo: And then run your code with "+RTS -sstderr" to get GC statistics
ph88 2017-02-21 03:21:06
i was looking at this tutorial https://generics-eot.readthedocs.io/en/latest/tutorial.html#th-example-meta-information-with-types-generating-sql-schemas and wondering if this does allow me to find a field of a certain type in a data structure, can i test for a specific type and then change the value? does someone know?
warbo 2017-02-21 03:21:49
merijn: hmm, I was afraid of that; might as well just use /usr/bin/time in that case
warbo 2017-02-21 03:21:51
thanks
merijn 2017-02-21 03:22:05
warbo: How so?
merijn 2017-02-21 03:22:25
warbo: Time measures runtime, profiling measures GC time, allocation rate, max residency, etc.
warbo 2017-02-21 03:23:33
time can report memory usage, page faults, context switches, etc. as well
merijn 2017-02-21 03:23:52
warbo: Sounds like you're using a non-POSIX time?
warbo 2017-02-21 03:24:01
yup
warbo 2017-02-21 03:24:09
GHC is a non-POSIX program too
warbo 2017-02-21 03:24:13
so nothing lost ;)
merijn 2017-02-21 03:24:45
warbo: Anyway, I'd still use profiling, because that can also give you call stacks and produce graphs *where* memory is allocated in the source
merijn 2017-02-21 03:25:03
warbo: So it will almost certainly be more useful for analysing your results
warbo 2017-02-21 03:25:37
merijn: I already have a bunch of test cases, using various hash implementations on data of various sizes
warbo 2017-02-21 03:25:58
but I've been running them through weigh, which tells me that they all use a bunch of memory
warbo 2017-02-21 03:26:50
but doesn't tell me whether that was being allocated and collected in small chunks, or building up
warbo 2017-02-21 03:27:23
the only indication I have is to watch `top` as it runs
merijn 2017-02-21 03:27:44
I just don't really understand the reason not to use GHC's profiling, given that it provides you A LOT of very detailed info
warbo 2017-02-21 03:28:21
I mostly don't want to wait all day for all my dependencies to be built with profiling enabled
warbo 2017-02-21 03:28:45
I've done it before, and it took several hours
merijn 2017-02-21 03:28:55
warbo: Ah, are you using cabal or stack?
warbo 2017-02-21 03:28:59
Nix
warbo 2017-02-21 03:29:05
with cabal
warbo 2017-02-21 03:30:02
I've spend many hours trying to make stack run; might as well have been banging my head against a wall ;)
merijn 2017-02-21 03:30:03
warbo: For the future: edit your ~/.cabal/config and set "library-profiling: True" that makes cabal always build profiling versions when installing libraries
warbo 2017-02-21 03:32:02
I don't like my builds depending on personal preferences
merijn 2017-02-21 03:32:09
warbo: That way you will always already have profiling libraries build whenever you decide you want to profile stuff (at the cost of making installs slightly slower, since it always builds profiling...)
merijn 2017-02-21 03:34:10
warbo: How does it make your build depend on personal preferences?
warbo 2017-02-21 03:34:10
I've got a dedicated set of `profiledHaskellPackages`, with profiled libraries for GHC 7.8.4, 7.10.3, 8.0.1, etc.
merijn 2017-02-21 03:34:10
warbo: By default it will still use non-profiling versions
merijn 2017-02-21 03:34:10
It just means that when you realise "I want to profile this" you will already preemptively have the profiling versions installed too
warbo 2017-02-21 03:34:10
I don't have *any* Haskell packages installed
warbo 2017-02-21 03:34:10
because I use Nix
merijn 2017-02-21 03:34:10
I'm sure Nix has some way to do the same (at least, so I hope...)
warbo 2017-02-21 03:34:10
(well, I do have a minimal GHC installed, so I can do Prelude stuff in GHCi)
warbo 2017-02-21 03:34:10
Nix is lazy
warbo 2017-02-21 03:34:10
it builds stuff as needed
warbo 2017-02-21 03:34:10
if profiled versions weren't needed, they won't be built
warbo 2017-02-21 03:34:10
until asked for, then they're all built at once
merijn 2017-02-21 03:34:10
Well, I guess that means I can preemptively scratch learning Nix of my todo list :)
bollu 2017-02-21 03:34:46
is there a way to have a parser combinator that accepts a token based on a predicate?
bollu 2017-02-21 03:34:57
I'm trying to look for such a combinator but I can't find one
bollu 2017-02-21 03:35:04
in Parsec
ahihi 2017-02-21 03:35:21
satisfy?
mauke 2017-02-21 03:41:19
> div 12 (-5)
lambdabot 2017-02-21 03:41:22
-3
mauke 2017-02-21 03:41:47
> (/) 12 (-5)
lambdabot 2017-02-21 03:41:51
-2.4
mauke 2017-02-21 03:41:57
> floor ((/) 12 (-5))
lambdabot 2017-02-21 03:42:01
-3