Search Haskell Channel Logs

Sunday, January 29, 2017

#haskell channel featuring recur22, lambdabot, Koterpillar, SrPx, joehillen, Tuplanolla,

joehillen 2017-01-29 12:26:16
:t (&)
lambdabot 2017-01-29 12:26:18
a -> (a -> b) -> b
recur22 2017-01-29 12:38:17
dose anyone know good example on how stdin stdout is used to call haskell as backend
SrPx 2017-01-29 12:38:40
Is there any easy way to, given an int `n`, get a list of all strings of length `n^2` containing `n` occurrences of every `x < n`? E.g., for 2, that would be: 0011, 0101, 1001, 0101, 0110, 1100
SrPx 2017-01-29 12:39:14
For 3, that would be: 000111222, 001011222, 010011222, 100011222, 100101222...
Koterpillar 2017-01-29 12:40:11
SrPx: it looks like you'd benefit from permutations :: [a] -> [[a]]
Koterpillar 2017-01-29 12:40:26
...which is in Data.List
Koterpillar 2017-01-29 12:40:59
> permutations "0011"
lambdabot 2017-01-29 12:41:02
["0011","0011","1001","0101","1001","0101","1100","1100","1010","1010","0110...
SrPx 2017-01-29 12:42:30
> foldl (\s x -> if x `elem` s then s else s ++ [x]) [] [1,2,3,1,1,2]
lambdabot 2017-01-29 12:42:33
[1,2,3]
SrPx 2017-01-29 12:42:45
> foldl (\s x -> if x `elem` s then s else s ++ [x]) [] [1,2,3,1,1,2] $ permutations "0011"
lambdabot 2017-01-29 12:42:48
error:
lambdabot 2017-01-29 12:42:48
• Couldn't match expected type '[[Char]] -> t'
lambdabot 2017-01-29 12:42:48
with actual type '[Integer]'
SrPx 2017-01-29 12:42:56
> foldl (\s x -> if x `elem` s then s else s ++ [x]) [] [1,2,3,1,1,2] $ permutations [0,0,1,1]
lambdabot 2017-01-29 12:42:58
error:
lambdabot 2017-01-29 12:42:58
• Couldn't match expected type '[[Integer]] -> t'
lambdabot 2017-01-29 12:42:58
with actual type '[Integer]'
SrPx 2017-01-29 12:43:18
> foldl (\s x -> if x `elem` s then s else s ++ [x]) [] $ permutations [0,0,1,1]
lambdabot 2017-01-29 12:43:21
[[0,0,1,1],[1,0,0,1],[0,1,0,1],[1,1,0,0],[1,0,1,0],[0,1,1,0]]
Koterpillar 2017-01-29 12:43:25
nub "0011001"
Koterpillar 2017-01-29 12:43:27
> nub "0011001"
lambdabot 2017-01-29 12:43:29
"01"
SrPx 2017-01-29 12:43:37
> nub $ permutations [0,0,0,1,1,1,2,2,2]
lambdabot 2017-01-29 12:43:40
[[0,0,0,1,1,1,2,2,2],[1,0,0,0,1,1,2,2,2],[0,1,0,0,1,1,2,2,2],[0,0,1,0,1,1,2,...
Tuplanolla 2017-01-29 12:43:45
This question feels familiar.
Koterpillar 2017-01-29 12:43:49
(beware that nub is O(n^2))
SrPx 2017-01-29 12:43:49
Interesting...
Koterpillar 2017-01-29 12:43:56
:t nub
lambdabot 2017-01-29 12:43:58
Eq a => [a] -> [a]
Koterpillar 2017-01-29 12:44:09
you can do better with Ord a
SrPx 2017-01-29 12:44:14
Koterpillar: why if it can easily be done in O(log(N)*N)?
SrPx 2017-01-29 12:44:42
Tuplanolla: why?
Koterpillar 2017-01-29 12:45:00
SrPx: nope, you need to check every incoming element against every element you've seen