Squarism 2017-01-27 11:46:23
List has function "all" but not Set. I think Set could have had it too - but im just a noob.
monochrom 2017-01-27 11:46:23
There are ways to set up empirical experiments so you don't have to read source code.
orzo 2017-01-27 11:46:25
i'm not trying to argue for some logical proof of a theorem here, just looking for a rule of thumb for pratcial coding
monochrom 2017-01-27 11:47:07
For example if you wonder whether Data.Map is eager or lazy in its skeleton structure, you can try building an infinitely large map and see what happens.
orzo 2017-01-27 11:47:07
:t all
lambdabot 2017-01-27 11:47:09
Foldable t => (a -> Bool) -> t a -> Bool
orzo 2017-01-27 11:47:15
Set is not Foldable?
monochrom 2017-01-27 11:47:52
I support practical programming too.
Naughtmare[m] 2017-01-27 11:47:52
orzo: set is not a functor.
Squarism 2017-01-27 11:47:55
ph it is
Squarism 2017-01-27 11:48:06
oh
monochrom 2017-01-27 11:48:20
The rule of thumb in this case is "you have to find out"
Zemyla 2017-01-27 11:48:40
Oh, edwardk, I realized why Cokleisli can't be a conforming Choice profunctor.
jle` 2017-01-27 11:48:45
Set should be foldable
geekosaur 2017-01-27 11:48:54
it is according to ghci
Squarism 2017-01-27 11:49:05
theres no docs that show what inherited methods a type has?
edwardk 2017-01-27 11:49:15
Zemyla: i need an isleftadjoint class
Zemyla 2017-01-27 11:50:03
Well, Cokleisli is closed, and it's apparently Strong, too. So if it were Choice as well, then I'm pretty sure that it would be able to be made an instance of Mapping.
monochrom 2017-01-27 11:50:34
You know what, it's all the more ironic because all the practical programmers I run into, they say "dig into the source code" more often than they say "you don't have to dig into the source code".
monochrom 2017-01-27 11:50:51
I am against that, but you brought up practical programming.
geekosaur 2017-01-27 11:50:51
Squarism, haddock shows instances (although recent versions have bugs that drop some instances)
edwardk 2017-01-27 11:50:59
the real constraint you want is something like f a is isomorphic to (x, a) for some 'x'
geekosaur 2017-01-27 11:51:03
there is no such thing as "inherited instances"
orzo 2017-01-27 11:51:05
monochrome, you're being an ass, spare me.
monochrom 2017-01-27 11:51:13
Whereas it is instead the theorists who say "that's immoral".
binary 2017-01-27 11:51:16
I'm curious about the density of *derived* Binary instance vs a hand-written instance
edwardk 2017-01-27 11:51:18
that lets you write a real costrength
binary 2017-01-27 11:51:40
Looking at the old Binary deriving implementation: https://hackage.haskell.org/package/binary-derive-0.1.0/docs/src/Data-Binary-Derive.html#derivePut
Zemyla 2017-01-27 11:51:47
And I'm like 90% sure that any Arrow that is Mapping has to be isomorphic to Indexed i for some i.
binary 2017-01-27 11:51:53
It doesn't look like it'd be too great, but maybe I don't get it
edwardk 2017-01-27 11:51:57
my recollection is that is what is needed to fix cokleisli/costar's choice instance
Squarism 2017-01-27 11:53:08
geekosaur, Yeah i see that. But some types have like 30 instances so its a bit offputting to glance through all of them. =D
Zemyla 2017-01-27 11:53:11
Ahh, okay. So it is isomorphic to Indexed i.
edwardk 2017-01-27 11:53:30
once you know you have (f a -> b) and that f a ~ (x, a) then you can play currying games, because f a -> b ~ (x, a) -> b ~ (x -> a -> b) ~ a -> (x -> b)
binary 2017-01-27 11:53:38
Does anyone have experience with making Binary instances as compact as possible?
edwardk 2017-01-27 11:53:50
yeah
edwardk 2017-01-27 11:54:13
once you have that you can do things like traverse with it
Squarism 2017-01-27 11:54:23
geekosaur, but good to know inherited mehtods arent listed anyway
geekosaur 2017-01-27 11:54:29
...
geekosaur 2017-01-27 11:54:42
could you explain what you think an inherited method is?
geekosaur 2017-01-27 11:54:51
they're "not listed" because there is no such thing. this is not OOP
edwardk 2017-01-27 11:55:01
anyways i need to come up with a good name for the existential form of that where you don't get to know 'x' and the form where you do, which are analogous to distributive and representable
geekosaur 2017-01-27 11:55:30
class Foo a => Bar a does not mean "Bar a inherits from Foo a", it means "Bar a must have an instance of Foo a"
edwardk 2017-01-27 11:55:33
then profunctors can get correct choice instances for cokleisli/costar
geekosaur 2017-01-27 11:55:40
you still have to provide that instance, it is not inherited
orzo 2017-01-27 11:56:06
that's called interface inheritence, geekosaur
geekosaur 2017-01-27 11:56:11
* an instance of Bar a must have ...
binary 2017-01-27 11:56:16
Okay, sounds like no one has much experience with derived vs hand-written Binary. If anyone has the knowledge, it'd be great to have some info on this in the https://hackage.haskell.org/package/binary docs.
Zemyla 2017-01-27 11:57:24
edwardk: Wouldn't the relevant method be something along the lines of Functor m => (a -> m b) -> f a -> m (f b)?
Zemyla 2017-01-27 11:57:28
Basically a lens?
glguy 2017-01-27 11:57:39
binary: You're unlikely to get much help with questions like "Does anyone have experience with..." questions
edwardk 2017-01-27 11:57:51
exactly
Zemyla 2017-01-27 11:57:54
And probably derive from Traversable1.
edwardk 2017-01-27 11:57:59
its a fancy subclass of Traversable
edwardk 2017-01-27 11:58:24
that is the existential version
edwardk 2017-01-27 11:58:53
the distributive analogue looks like that anyways
edwardk 2017-01-27 11:59:06
the representable one needs a type family to talk about 'x'
Zemyla 2017-01-27 12:03:45
edwardk: Is there a way to describe a Traversable f as f a ~ exists n. (x n, Vect n a)?
edwardk 2017-01-27 12:04:17
thats not quite right sadly, because traversable allows infinite containers
edwardk 2017-01-27 12:04:45
and the infinite descent isn't on one side like [a] all the time
Zemyla 2017-01-27 12:05:15
Well, n wouldn't be a number. It'd be a potentially-infinite countable ordinal.
edwardk 2017-01-27 12:05:19
its a good intuition for the finite cases
edwardk 2017-01-27 12:05:55
the problem is that you don't have the ability to necessariy re-associate things to put elements in place
edwardk 2017-01-27 12:09:14
even just an infinite tree gets you in trouble with that intuition. data Tree a = Bin (Tree a) a (Tree a) | Tip deriving (Functor,Foldable,Traversable); tree = Bin tree 1 tree has infinite recursions all over the place all over the place, but is still traversable (with or without Tip being a member)
edwardk 2017-01-27 12:09:42
you can come up with applicatives that can produce meaningful answers traversing that silliness
Zemyla 2017-01-27 12:11:18
Is there a way to turn a Magma into a breadth-first traversal?
Squarism 2017-01-27 12:14:03
what would be a short way of checking duplicates in a list?
Squarism 2017-01-27 12:14:13
i suspect such function exist
Cale 2017-01-27 12:14:40
(\xs -> xs == nub xs) is short
Zemyla 2017-01-27 12:15:15
That'd be something along the lines of zipping both halves of a fork when it happens...
jle` 2017-01-27 12:16:29
(\xs -> length xs == length (S.fromList xs)) might be more efficient but hwo knows
jle` 2017-01-27 12:16:39
(it requires an Ord instance tho)
Cale 2017-01-27 12:17:09
If I was worried about performance, I'd replace nub with something like
Cale 2017-01-27 12:18:30
@let ordNub xs = foldr (\x xs s -> if S.member x s then xs s else xs (S.insert x s)) (const []) xs S.empty
lambdabot 2017-01-27 12:18:34
Defined.
Zemyla 2017-01-27 12:19:07
This is faster and more general.
Zemyla 2017-01-27 12:19:42
@let checkUnique l = foldr (\a r s -> S.notMember a s && r (S.insert a s)) (const True) l S.empty
lambdabot 2017-01-27 12:19:44
Defined.
Cale 2017-01-27 12:19:53
oops, missed the element :)
Zemyla 2017-01-27 12:20:04
That way, you aren't accumulating stuff you don't need.
Cale 2017-01-27 12:20:07
@let ordNub xs = foldr (\x xs s -> if S.member x s then xs s else x : xs (S.insert x s)) (const []) xs S.empty
lambdabot 2017-01-27 12:20:09
.L.hs:179:1: warning: [-Woverlapping-patterns]
lambdabot 2017-01-27 12:20:09
Pattern match is redundant
lambdabot 2017-01-27 12:20:09
In an equation for 'ordNub': ordNub xs = ...
Cale 2017-01-27 12:20:13
right...
Cale 2017-01-27 12:20:19
@undefine
jle` 2017-01-27 12:20:19
wait, isn't there an ordNub in base now? or was i dreaming when i raed that there was
lambdabot 2017-01-27 12:20:19
Undefined.
Cale 2017-01-27 12:20:24
ordNub xs = foldr (\x xs s -> if S.member x s then xs s else x : xs (S.insert x s)) (const []) xs S.empty
Cale 2017-01-27 12:20:26
@let ordNub xs = foldr (\x xs s -> if S.member x s then xs s else x : xs (S.insert x s)) (const []) xs S.empty
lambdabot 2017-01-27 12:20:28
Defined.
Cale 2017-01-27 12:20:31
@let checkUnique l = foldr (\a r s -> S.notMember a s && r (S.insert a s)) (const True) l S.empty
lambdabot 2017-01-27 12:20:33
Defined.
Zemyla 2017-01-27 12:20:47
> checkUnique [1, 2, 3, 1, 4]
lambdabot 2017-01-27 12:20:50
False
Cale 2017-01-27 12:22:03
It should amount to *approximately* the same thing using ordNub and (==), due to laziness
Cale 2017-01-27 12:22:25
But you'll end up doing more equality tests
Zemyla 2017-01-27 12:22:27
:t checkUnique
lambdabot 2017-01-27 12:22:29
(Foldable t, Ord a) => t a -> Bool
Zemyla 2017-01-27 12:22:37
My function is more general.
Cale 2017-01-27 12:23:12
Ah, I suppose this ordNub simultaneously converts to a list
Cale 2017-01-27 12:23:31
So you'd have to write ordNub xs == toList xs
Zemyla 2017-01-27 12:23:46
And then you're folding over the list twice.
Cale 2017-01-27 12:24:39
Yeah, but it's not terrible, since the traversal happens in parallel
Zemyla 2017-01-27 12:24:57
Yes, but you should avoid doing more than you need to.
Cale 2017-01-27 12:24:58
(so early elements in the list can become garbage)
Zemyla 2017-01-27 12:26:05
Also, your solution prevents things like stream fusion if used with vectors.
RandoCoder 2017-01-27 12:26:22
Is there a function that has type Monad m => m a -> (a -> b) -> m b?
RandoCoder 2017-01-27 12:26:48
The closest I can find is flip fmap
Zemyla 2017-01-27 12:28:03
:t (<&>) -- RandoCoder
lambdabot 2017-01-27 12:28:05
Functor f => f a -> (a -> b) -> f b
seequ_ 2017-01-27 12:28:09
RandoCoder: fmap is probably what you want
RandoCoder 2017-01-27 12:29:05
Thanks
biglambda 2017-01-27 12:36:51
When does stack build execute Setup.hs?