Xnuk 2017-03-03 16:55:34
@hoogle (Monad m1, Monad m2) => m1 (m2 x) -> (x -> m1 (m2 y)) -> m1 (m2 y)
lambdabot 2017-03-03 16:55:37
Data.Functor.Syntax (<.*$>) :: Functor f0 => (c -> d) -> f0 (a -> b -> c) -> f0 (a -> b -> d)
lambdabot 2017-03-03 16:55:37
Data.Functor.Syntax (<*.$>) :: Functor f0 => (a -> c -> d) -> f0 (b -> c) -> f0 (a -> b -> d)
lambdabot 2017-03-03 16:55:37
Data.Functor.Syntax (<~~~$>) :: Functor f0 => (a -> b -> c -> d -> e) -> f0 d -> f0 (a -> b -> c -> e)
arkasis 2017-03-03 17:04:17
I have a question; I don't understand the error messages -> http://lpaste.net/353201
dmj` 2017-03-03 17:06:16
arkasis: usage of map here is suspect
dmj` 2017-03-03 17:06:19
map a (\c i ->
dmj` 2017-03-03 17:06:24
on line 20
arkasis 2017-03-03 17:07:21
the problem is the syntax? (or semantics?
dmj` 2017-03-03 17:09:31
:t map
lambdabot 2017-03-03 17:09:33
(a -> b) -> [a] -> [b]
dmj` 2017-03-03 17:09:59
the type of addition you have is :: [Bit] -> [Bit] -> [Bit]
dmj` 2017-03-03 17:10:27
which means the type of the a parameter is also [Bit], which is being passed to the first argument of map
dmj` 2017-03-03 17:10:47
map is expecting (a -> b) and you're providing [Bit]
dmj` 2017-03-03 17:11:17
which is the first error
doyougnu 2017-03-03 17:11:29
roughly speaking, map expects a function and a list. The way you've written it "a" is the function you pass to map, so you get a type error when you try to pass the lambda function "(\c i -> ...)"
arkasis 2017-03-03 17:11:52
hm... I'm going to try again
arkasis 2017-03-03 17:11:55
thanks
doyougnu 2017-03-03 17:11:59
because that is not a list
dmj` 2017-03-03 17:12:40
arkasis is your assumption that a should be a list and the lambda the index and value?
arkasis 2017-03-03 17:13:28
yes, because I come from javascript
dmj` 2017-03-03 17:13:29
and once addition does type check, that map function will never be evaluated since it always returns [True]
arkasis 2017-03-03 17:14:14
ok, I'm have to check the type of map
dmj` 2017-03-03 17:14:18
arkasis: ok, well that's fine. Haskell does have some functions that allow one to traverse over a structure with both value and index
dmj` 2017-03-03 17:15:50
I'll let you experiment though
doyougnu 2017-03-03 17:16:17
^^ best way to learn
arkasis 2017-03-03 17:16:28
I prefer to know the name of that function (?
arkasis 2017-03-03 17:18:39
nvm, I think I can make that function and learn haskell on the way
dmj` 2017-03-03 17:20:39
arkasis: since haskell is lazy, it's often times nice to generate a parallel list that corresponds to the indexes, and then zip them together
dmj` 2017-03-03 17:21:31
:t \f xs -> map f $ zip xs [0..]
lambdabot 2017-03-03 17:21:33
(Num b1, Enum b1) => ((a, b1) -> b) -> [a] -> [b]
arkasis 2017-03-03 17:22:59
seems a bit complicated for me at the moment
dmj` 2017-03-03 17:24:17
arkasis: then we can uncurry f to get the function you were looking for
dmj` 2017-03-03 17:24:23
:t \f xs -> map (uncurry f) $ zip xs [0..]
lambdabot 2017-03-03 17:24:25
(Num b1, Enum b1) => (a -> b1 -> b) -> [a] -> [b]
arkasis 2017-03-03 17:25:10
@____@
lambdabot 2017-03-03 17:25:11
Unknown command, try @list
dmj` 2017-03-03 17:25:15
where b1 is the type of your index, 'a' is the value, and 'b' is the type of what you're returning
Sornaensis 2017-03-03 17:25:36
@list
lambdabot 2017-03-03 17:25:36
What module? Try @listmodules for some ideas.
Welkin 2017-03-03 17:26:05
!list
Welkin 2017-03-03 17:26:10
show me your fserves!
Wizek 2017-03-03 17:29:42
hi, Anyone knows of a function `:: (Char -> IO String) -> Handle -> IO Handle` that would allow to map over a readable stream?
drostie 2017-03-03 17:33:25
Wizek: you want to run a program on every character read from a handle?
Wizek 2017-03-03 17:33:39
I'm launching a child-process, and I'd like to redirect its stdout to the main process'es stdout in a way that distinguishes both streams, e.g. indent the children's output. I imagine maybe using it something like this: `f (\case '\n' -> return " \n"; a -> return a) childHandle >>= dupTo stdout`
drostie 2017-03-03 17:33:41
Wizek: and then ignore the strings that those programs produce?
pikajude 2017-03-03 17:35:16
wouldn't it be "\n "
Wizek 2017-03-03 17:35:27
pikajude, yes, good catch
pikajude 2017-03-03 17:35:32
i tried
Wizek 2017-03-03 17:37:18
drostie, I don't think I'd want to run a program on every character, no. In fact, in my particular usecase `(Char -> String) -> Handle -> IO Handle` may be sufficient too.
Wizek 2017-03-03 17:38:28
the reason I thought to have the function parameter monadic is to allow handling stateful decisions too, e.g. change all 'a' to 'b' only if it was preceeded by 'c'
Wizek 2017-03-03 17:39:05
But that's a more general usecase I don't directly care about right now.
Wizek 2017-03-03 17:42:07
Also, I thought to write this function myself, the thing that's keeping me is it doesn't seem to be easy to create a mock Handle to simulate for tests. But maybe I'll more along those lines