Bool[Map[K, V:Bool]]

17 views
Skip to first unread message

Alec Zorab

unread,
Dec 5, 2014, 11:07:49 AM12/5/14
to spire...@googlegroups.com
All,

I feel as though it should be the case that we can provide a boolean algebra for maps of bools. That said I'm finding it hard to actually write it, primarily because the Map interface has a slightly odd on-off relationship with default values.

I've created a rough sketch here [1] but it falls over on calls to default value.

Is there some way I can do this without following the approach in the infset example of having separate finite and infinite types?


Tom Switzer

unread,
Dec 5, 2014, 11:32:29 AM12/5/14
to Alec Zorab, Spire User List
Yeah, unfortunately I think Map's withDefaultValue is too weird to be reliable. It only works when you treat Map like a function and none of the other map methods really support it.

I think you are stuck with creating a special type, like infset, to deal with this, since you'll need to restrict the interface to deal with the infinite nature of the type.

You may also be interested in the latest vector space refactor PR, which introduces the concept of a basis, and may make the map operations easier to implement: https://github.com/non/spire/pull/334

Erik Osheim

unread,
Dec 5, 2014, 11:37:16 AM12/5/14
to Tom Switzer, Alec Zorab, Spire User List
Yeah, I agree that using default values with maps doesn't work very well.

You can treat a Map as a Function1, which does work. Or you could
manually encode your own "infset" using Either if you wanted. But
yeah, unfortunately there isn't a good built-in collection for this
kind of thing.

-- Erik

On Fri, Dec 05, 2014 at 11:32:28AM -0500, Tom Switzer wrote:
> Yeah, unfortunately I think Map's withDefaultValue is too weird to be
> reliable. It only works when you treat Map like a function and none of the
> other map methods really support it.
>
> I think you are stuck with creating a special type, like infset, to deal
> with this, since you'll need to restrict the interface to deal with the
> infinite nature of the type.
>
> You may also be interested in the latest vector space refactor PR, which
> introduces the concept of a basis, and may make the map operations easier
> to implement: https://github.com/non/spire/pull/334
>
> On Fri, Dec 5, 2014 at 11:07 AM, Alec Zorab <alec...@gmail.com> wrote:
>
> > All,
> >
> > I feel as though it should be the case that we can provide a boolean
> > algebra for maps of bools. That said I'm finding it hard to actually write
> > it, primarily because the Map interface has a slightly odd on-off
> > relationship with default values.
> >
> > I've created a rough sketch here [1]
> > <https://gist.github.com/AlecZorab/b6a71d6ed9d6df97cbc7> but it falls

Erik Osheim

unread,
Dec 5, 2014, 11:49:11 AM12/5/14
to Tom Switzer, Alec Zorab, Spire User List
Relatedly, I wonder if I should release some of these infinite set/map
implementations somewhere? Do you all think that would be useful?

-- Erik

Alec Zorab

unread,
Dec 5, 2014, 11:58:24 AM12/5/14
to Erik Osheim, Tom Switzer, Spire User List
Certainly for me it would. I actually want to represent calendars as sets of Dates, so I've already had to hack out something fairly similar to the infset example to handle that.

If I had nicely behaved infinite sets and maps I could throw all that code away and replace it all with a one liner :)
Reply all
Reply to author
Forward
0 new messages