These are chat archives for non/algebra

13th
Dec 2015
Rüdiger Klaehn
@rklaehn
Dec 13 2015 08:55
I published a number of data structures that use the algebra typeclasses:
https://github.com/rklaehn/abc
For both of these it would be really helpful if there was a `Hash[A]` in algebra. Also, it would be good if the recent additions to the lattice typeclasses would make their way to maven.
Dec 13 2015 09:14
@rklaehn you prob know this but theres a WIP on non/algebra#38
Denis Rosset
@denisrosset
Dec 13 2015 18:56
@rklaehn: this is a tricky one. If you want a vector space of vectors with arbitrary lengths, then you have to pretend that vectors have an infinite number of indices, of which only a finite number are zero --- that's where the AdditiveMonoid joins the party.
The problem also arises when you want to write a Ring of matrices of arbitrary sizes: without dependent types, it's impossible to make it typesafe and usable. You could define a matrix with the same trick (i.e., all non-specified elements are = 0), but then you run into trouble when you define the "one" element.
Rüdiger Klaehn
@rklaehn
Dec 13 2015 19:34
Wouldn't the correct solution for this be to have a distinct type for "Map with default value" (TotalMap)? Then you could just have a TotalMap with default value of Ring.zero and define your instances.
I don't have a problem with instances like Group that require a non-standard definition of equality. I just don't want them (and the non-standard Eq) to be in the implicit scope by default.
Cody Allen
@ceedubs
Dec 13 2015 19:41
@rklaehn fwiw, a distinct type for a Map with a default value is something that I’ve found myself wanting in the past. It is awkward to deal with `get` returning an `Option` when you know that it won’t. And calling the unsafe `apply` method on the standard collection Map seems like it’s asking for trouble if someone decides to change how the Map is created
(I admit to not reading all of the background context, so ignore me if I’m saying irrelevant things)
Rüdiger Klaehn
@rklaehn
Dec 13 2015 19:52
It would be easy enough to write one in project https://github.com/rklaehn/abc . What would be a good name (I am terrible coming up with names)? TotalMap?
I already got NegatableArraySet, which is a Set with an extra boolean so you can define a algebra.lattice.Bool instance for it.
Cody Allen
@ceedubs
Dec 13 2015 19:55
@rklaehn it looks like you are up to some neat stuff. `TotalMap` sounds good to me. I like it a little more than something like `MapWithDefault`, because I could imagine that you might want to also be able to instantiate one with a default method to run on the key that is requested, as opposed to just a single static default value
Rüdiger Klaehn
@rklaehn
Dec 13 2015 19:56
The problem with a default method instead of a default value is that it would then become impossible to define a meaningful Eq for it, right?
Cody Allen
@ceedubs
Dec 13 2015 19:56
ah yes, that’s true
maybe that’s yet another distinct type :)
Rüdiger Klaehn
@rklaehn
Dec 13 2015 19:58
Nothing wrong with having different types for different concepts :-) I heard that is all the rage these days...
Cody Allen
@ceedubs
Dec 13 2015 19:58
:D
agreed
Rüdiger Klaehn
@rklaehn
Dec 13 2015 19:59
Seriously, I hate it that for a scala.collection.immutable.Map I can not tell if it is lazy or not (mapValues / filterKeys), if it has a default value or not etc.
Cody Allen
@ceedubs
Dec 13 2015 20:00
yeah, I think there are no shortage of people who have been bitten with bugs related to those aspects of std lib `Map`