Tuplanolla 2017-01-29 12:45:32
It comes up when indexing lexicographic permutations, which I seem to find myself doing all the time, SrPx.
SrPx 2017-01-29 12:45:35
Koterpillar: with that type yes, but why isn't `nub` requiring Ord to begin with?
Koterpillar 2017-01-29 12:46:02
SrPx: oversight/legacy reasons
Tuplanolla 2017-01-29 12:46:22
Note that `permutations` doesn't return them in lexicographic order either.
geekosaur 2017-01-29 12:46:33
@index nubOrd
lambdabot 2017-01-29 12:46:33
bzzt
SrPx 2017-01-29 12:46:47
Tuplanolla: hmm... interesting. I guess the permutations implementation is fine but probably sub par. I wonder what is the more direct recursive algorithm
Koterpillar 2017-01-29 12:46:58
SrPx: it's under ordNub everywhere: http://hayoo.fh-wedel.de/?query=Ord+a+%3D%3E+%5Ba%5D+-%3E+%5Ba%5D
Tuplanolla 2017-01-29 12:47:18
@let picks (x : xs) = (x, xs) : [(y, x : ys) | (y, ys) <- picks xs]; picks [] = []
lambdabot 2017-01-29 12:47:20
Defined.
Tuplanolla 2017-01-29 12:47:40
@let perms xs = [y : zs | (y, ys) <- picks xs, zs <- perms ys]; perms [] = [[]]
lambdabot 2017-01-29 12:47:42
.L.hs:160:1: warning: [-Woverlapping-patterns]
lambdabot 2017-01-29 12:47:42
Pattern match is redundant
lambdabot 2017-01-29 12:47:42
In an equation for 'perms': perms [] = ...
Koterpillar 2017-01-29 12:47:46
SrPx: you would be better off keeping counts of how many times did you emit each element
Tuplanolla 2017-01-29 12:47:55
Damn it.
Tuplanolla 2017-01-29 12:47:59
@undefine
lambdabot 2017-01-29 12:47:59
Undefined.
Tuplanolla 2017-01-29 12:48:35
@let perms [] = [[]]; perms xs = [y : zs | (y, ys) <- picks xs, zs <- perms ys]
lambdabot 2017-01-29 12:48:37
Defined.
Tuplanolla 2017-01-29 12:48:50
> perms [0 .. 4]
lambdabot 2017-01-29 12:48:52
[[0,1,2,3,4],[0,1,2,4,3],[0,1,3,2,4],[0,1,3,4,2],[0,1,4,2,3],[0,1,4,3,2],[0,...
Tuplanolla 2017-01-29 12:49:10
> permutations [0 .. 4]
lambdabot 2017-01-29 12:49:12
[[0,1,2,3,4],[1,0,2,3,4],[2,1,0,3,4],[1,2,0,3,4],[2,0,1,3,4],[0,2,1,3,4],[3,...
Zemyla 2017-01-29 12:50:48
I just came up with a Stupid Haskell Trick.
Zemyla 2017-01-29 12:50:56
Set -XOverloadedStrings, then define:
Zemyla 2017-01-29 12:51:01
@let instance (a ~ [Char], IsString b) => IsString (a -> b) where fromString s = fromString . (++) s
lambdabot 2017-01-29 12:51:02
Defined.
Zemyla 2017-01-29 12:51:19
Then something like "long" "literal" "string" becomes "longliteralstring".
Tuplanolla 2017-01-29 12:51:22
The point is that `perms = fmap reverse . permutations . reverse` does not hold, SrPx.
Koterpillar 2017-01-29 12:51:31
> "long" "literal" "string"
lambdabot 2017-01-29 12:51:33
error:
lambdabot 2017-01-29 12:51:33
• Couldn't match expected type '[Char] -> [Char] -> t'
lambdabot 2017-01-29 12:51:33
with actual type '[Char]'
Zemyla 2017-01-29 12:51:45
lambdabot doesn't have OverloadedStrings set.
geekosaur 2017-01-29 12:52:25
what is this, C? >.>
Tuplanolla 2017-01-29 12:52:33
That's neat, Zemyla.
Tuplanolla 2017-01-29 12:52:54
I wonder if the type checker likes it.
Zemyla 2017-01-29 12:52:57
It also makes showString unnecessary in Show instances.
SrPx 2017-01-29 12:54:40
Tuplanolla: makes sense