gfixler 2017-02-20 00:47:44
> let x = 3; xs = [0..9] in map snd $ filter ((/=x) . fst) (zip [0..] xs)
lambdabot 2017-02-20 00:47:47
[0,1,2,4,5,6,7,8,9]
chpatrick 2017-02-20 00:52:45
is it possible to have a buildEnv that has the dependencies of haskell packages A and B without building either?
ongy 2017-02-20 00:55:11
if you can get the sources for A and B you can `cabal install --dependencies-only` both of them
ongy 2017-02-20 00:55:14
aaand I'm to late
flxw 2017-02-20 01:01:10
Hi. Could somebody please tell me if I am wrong, or if ghc-mod's refine command is not working for me. :-) Minimal example:
flxw 2017-02-20 01:01:16
f :: [Int] -> [Int]; f x = _a; main=return()
flxw 2017-02-20 01:01:58
When I try to refine _a by (:) it refines _a to (:) _a1 _a2.
flxw 2017-02-20 01:02:49
but when I try to refine by "filter", it does put in the word filter, but wothout the new holes fo rthe argumetns.
flxw 2017-02-20 01:04:04
ie. $ ghc-mod$ ghc-mod refine t.hs 1 28 filter
cocreature 2017-02-20 01:04:08
flxw: maybe it only works for constructors? I don't use ghc-mod so I sadly can't be of more help
flxw 2017-02-20 01:04:10
1 28 1 30 "filter"
flxw 2017-02-20 01:04:51
but the ad showed it with filter! ;_)
flxw 2017-02-20 01:05:01
*on
cocreature 2017-02-20 01:05:21
flxw: in that case reporting a bug is probably not a bad idea :)
flxw 2017-02-20 01:07:27
yeah. I haven't used ghc-mod before, so I wanted to at least check whether I'm completely off or not.
flxw 2017-02-20 01:08:24
Just for completeness sake: www.mew.org/~kazu/proj/ghc-mod/en/emacs.html
flxw 2017-02-20 01:09:42
but you'reright, I'll file a bug tonight. (I waswwant to try the repos HEAD before)
flxw 2017-02-20 01:10:12
*want
tabaqui1 2017-02-20 01:11:22
hi all
gfixler 2017-02-20 01:11:28
> liftA2 (++) fst snd $ (take 3 &&& drop (3 + 1)) "hello"
Schrostfutz 2017-02-20 01:11:30
The type of foldl is foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b. What is the -> t a doing in the definition? foldl takes only two paramerters, not three, doesn't it?
lambdabot 2017-02-20 01:11:31
"helo"
tabaqui1 2017-02-20 01:11:33
where can I find concurrency patterns in haskell?
tabaqui1 2017-02-20 01:11:58
I have to write some code, but in my naive implementation it's too complicated
gfixler 2017-02-20 01:12:03
tabaqui1:http://chimera.labs.oreilly.com/books/1230000000929
tabaqui1 2017-02-20 01:12:45
gfixler: looks fine, thanks
gfixler 2017-02-20 01:12:55
Schrostfutz: no, it takes 3
Schrostfutz 2017-02-20 01:13:33
gfixler: Oh, you're right, thanks.
gfixler 2017-02-20 01:13:44
Schrostfutz: it takes the fold function, the starting value/accumulator, then the value to operate on
gfixler 2017-02-20 01:14:33
Schrostfutz: have a look at the behavior of foldr, foldl, and foldl' if you haven't encountered anything about them yet
Schrostfutz 2017-02-20 01:15:36
gfixler: I'm currently trying to understand the implemenation of foldl using foldr which is described in readl world haskell.
quchen 2017-02-20 01:15:59
Hah, that's a tough one.
gfixler 2017-02-20 01:16:15
Schrostfutz: okay, I'm guessing that RWH goes over the issues with strictness and such
quchen 2017-02-20 01:16:24
I use it as a mental exercise every now and then ;-)
Schrostfutz 2017-02-20 01:16:26
quchen: Yeah, I noticed...
gfixler 2017-02-20 01:16:57
I should probably look through that again - it's been a couple of years, and I remember it being tough back then
quchen 2017-02-20 01:17:21
(And foldr does not have an accumulator by the way.)
quchen 2017-02-20 01:18:28
Schrostfutz: I wasn't able to come up with the solution when I heard about foldr-for-foldl, but studying the solution proved useful.
quchen 2017-02-20 01:18:56
Schrostfutz: Try evaluating foldrViaFoldl (+) 0 [1,2,3] by hand.
gfixler 2017-02-20 01:19:07
it doesn't?
gfixler 2017-02-20 01:19:09
:t foldr
lambdabot 2017-02-20 01:19:12
Foldable t => (a -> b -> b) -> b -> t a -> b
gfixler 2017-02-20 01:19:17
what's that b?
quchen 2017-02-20 01:19:20
(If you have the solution already. I could give it to you if you want.)
quchen 2017-02-20 01:19:37
b is the type of the resulting structure.
quchen 2017-02-20 01:19:49
?src foldr
lambdabot 2017-02-20 01:19:50
foldr f z [] = z
lambdabot 2017-02-20 01:19:50
foldr f z (x:xs) = f x (foldr f z xs)
Schrostfutz 2017-02-20 01:19:51
gfixler: I think it's not an accumulator but you rather use an 'init' value
quchen 2017-02-20 01:19:54
This accumulates nothing.
gfixler 2017-02-20 01:20:02
alright, semantics
Schrostfutz 2017-02-20 01:20:02
But my terminology is likely way of
gfixler 2017-02-20 01:20:14
I think of all the bs as b at different times
gfixler 2017-02-20 01:20:26
in the (a -> b -> b) it's the current and next b
quchen 2017-02-20 01:20:30
Semantics describe the meaning of things, and it's fairly important.
gfixler 2017-02-20 01:20:32
the b arg is the starting b
gfixler 2017-02-20 01:20:39
and the final b is the ultimate/resultant b
quchen 2017-02-20 01:23:07
No, the b arg is not the starting b.
quchen 2017-02-20 01:23:14
There is no starting b. There is an ending b.
quchen 2017-02-20 01:23:33
(The 2nd argument to foldr)
gfixler 2017-02-20 01:23:45
> foldr (+) 0 [1,2,3,4]
lambdabot 2017-02-20 01:23:49
10
gfixler 2017-02-20 01:23:51
> foldr (+) 5 [1,2,3,4]
lambdabot 2017-02-20 01:23:54
15
gfixler 2017-02-20 01:23:58
sure looks like a starting value to me
merijn 2017-02-20 01:24:17
> foldr f z [1..5] :: Expr
quchen 2017-02-20 01:24:18
> foldr (:) [] [1,2,3,4] -- [] is not a starting value.
lambdabot 2017-02-20 01:24:23
f 1 (f 2 (f 3 (f 4 (f 5 z))))
lambdabot 2017-02-20 01:24:24
[1,2,3,4]
merijn 2017-02-20 01:24:31
gfixler: Looks like an ending to me...
gfixler 2017-02-20 01:24:48
is that why I got out 0 and 5?
merijn 2017-02-20 01:25:09
> foldr (+) 5 [1..5] :: Expr
quchen 2017-02-20 01:25:11
In »foldr f z xs«, »z« is not touched until the entire list »xs« is traversed.
lambdabot 2017-02-20 01:25:13
1 + (2 + (3 + (4 + (5 + 5))))
gfixler 2017-02-20 01:25:31
are you talking about evaluation order?
quchen 2017-02-20 01:26:53
No. »foldl f z xs« recursively calls itself, and modifies the »z« in the process. That's why we say that »z« accumulates something.
quchen 2017-02-20 01:26:54
Foldr does not do this.
quchen 2017-02-20 01:27:21
There is no recursion in foldr that modifies part of it. It builds up a chain of function calls (as merijn demonstrated).
cocreature 2017-02-20 01:27:28
if you want to be pedantic: foldr for lists doesn't do this :)
quchen 2017-02-20 01:27:36
There is no field that is repeatedly modified to hold the result.
quchen 2017-02-20 01:27:47
cocreature: foldr for Foldable can do anything it wants because Foldable has no laws, so yeah.
gfixler 2017-02-20 01:28:05
I see where you're coming from now
gfixler 2017-02-20 01:28:10
and it was semantics
gfixler 2017-02-20 01:28:26
I wasn't concerned with the implementation of foldr under the hood
quchen 2017-02-20 01:28:29
Yes, it was semantics. Like calling »value« »rabbit« is semantics.
gfixler 2017-02-20 01:28:37
you sure are upset
quchen 2017-02-20 01:28:40
It likely leads to misunderstandings.
gfixler 2017-02-20 01:29:48
it's good, though, what you're doing
gfixler 2017-02-20 01:30:19
makes sure a lot of people more shy than me will never dare ask questions in here
Cooler 2017-02-20 01:30:51
why does fmap length $ (,) <$> getLine <*> getLine return 1?
Cooler 2017-02-20 01:31:07
>let x = fmap length $ (,) <$> getLine <*> getLine
liste 2017-02-20 01:31:33
Cooler: because the Foldable instance of (,) concerns just the first element
liste 2017-02-20 01:31:39
> length (1,2)
lambdabot 2017-02-20 01:31:42
1
liste 2017-02-20 01:32:29
Cooler: http://hackage.haskell.org/package/base-4.9.1.0/docs/src/Data.Foldable.html#line-305
liste 2017-02-20 01:32:43
the second element*
liste 2017-02-20 01:32:45
not the first
liste 2017-02-20 01:33:01
foldMap id (1,2)
liste 2017-02-20 01:33:03
> foldMap id (1,2)
lambdabot 2017-02-20 01:33:07
error:
lambdabot 2017-02-20 01:33:07
• Ambiguous type variable 'a0' arising from a use of 'show_M161567402854...
lambdabot 2017-02-20 01:33:08
prevents the constraint '(Show a0)' from being solved.
merijn 2017-02-20 01:33:21
liste: Numbers aren't monoids :p
liste 2017-02-20 01:33:24
yeah
liste 2017-02-20 01:33:25
:/
liste 2017-02-20 01:33:34
> toList (1,2)
lambdabot 2017-02-20 01:33:39
error:
lambdabot 2017-02-20 01:33:40
Ambiguous occurrence 'toList'
lambdabot 2017-02-20 01:33:40
It could refer to either 'F.toList',
liste 2017-02-20 01:33:51
results in [2]
quchen 2017-02-20 01:34:24
> F.toList (1,2)
lambdabot 2017-02-20 01:34:31
[2]
richardcq 2017-02-20 01:34:32
Hi guys. I'm building an application using hedis (for the redis key-value store) and control.concurrent, and I'm thinking that the best way to handle locking/unlocking would be with setup, tear down, and rollback on error functions and a global list of keep-lock-alive lambdas that the main thread goes through every so often. I think this is a use case for making my own monad, but I just wanted some suggestions to make sure I'm d
quchen 2017-02-20 01:40:49
Schrostfutz: Anyway, foldr in terms of foldr is a good riddle, but probably not necessary as a beginner. But it's a very interesting thing to learn about. The basic idea is that you can »add another parameter« to foldr that holds an arbitrary value, and then use that to implement an accumulator.
quchen 2017-02-20 01:41:03
Here are a bunch of simpler versions of the same idea: https://github.com/quchen/articles/blob/master/useful_techniques.md#bouncy-folds
quchen 2017-02-20 01:43:32
Schrostfutz: In the »find2nd« example, there is a Bool parameter which says whether something has been found already.
mbrock 2017-02-20 01:43:34
can I tell ghci to please optimize and compile the module I'm fiddling with?
quchen 2017-02-20 01:44:05
mbrock: You have to compile it externally, GHCi will load the compiled version if it's there I think
cocreature 2017-02-20 01:44:16
shouldn't -fobject-code help?
quchen 2017-02-20 01:44:34
Should it? That sounds interesting
cocreature 2017-02-20 01:44:50
I thought it does, but maybe I'm wrong
cocreature 2017-02-20 01:45:06
-fobject-code and -O2 if you want to optimize