You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is another very cool libraryuniverse, perhaps you're already aware of it, but briefly it is a library "for types where we know all the values". And I think it would be great to add instances of the Universe and Finite (Finite universes) classes for the data types in the smash library. I initially tried to add instances directly to the universe package, see dmwit/universe#62 but it was reasonably suggested that I should try to add the instances here first. The implementations are straight forward:
-- Data.Caninstance (Universea, Universeb) =>Universe (Canab) whereuniverse:: [Canab]
universe =fmap toCan universe
wheretoCan::Maybe (Theseab) ->Canab
toCan =maybeNon (these OneEnoTwo)
instance (Finitea, Finiteb) =>Finite (Canab) where-- 1 + a + b + abcardinality::Tagged (Canab) Natural
cardinality = liftA2 (\a b ->1+ a + b + a * b) (retag (cardinality ::TaggedaNatural)) (retag (cardinality ::TaggedbNatural))
universeF:: [Canab]
universeF =fmap toCan universeF
wheretoCan::Maybe (Either (Eitherab) (a, b)) ->Canab
toCan =maybeNon (either (eitherOneEno) (uncurryTwo))
And in the event the These type becomes available (either through this package or directly from the these package [I'll be opening a ticket there next]), toCan ideally would instead be written:
The cardinality feature is particularly awesome because it allows one to compute the cardinality efficiently using simple arithmetic instead of using the default definition which would expand the entire universe (i.e. create a list of all the values) and then have to take the length of said list.
I'm not sure if you're interested in adding these instances, I won't be offended if you aren't but I figure it is worth asking. Have a great day!
The text was updated successfully, but these errors were encountered:
subttle
changed the title
Consideration to add Universe and UniverseF instances for Wedge, Can, Smash
Consideration to add Universe and Finite instances for Wedge, Can, SmashApr 17, 2021
Hi @emilypi! :) No worries at all, thanks for letting me know. For now I'll just close the ticket if that's alright because of the issue you cited and additionally I'm not familiar with finitary (at a glance, however, it looks pretty cool). But if the issue you pointed to gets resolved and I end up familiarizing with finitary in order to rewrite the instances I'll post an update :) Thank you for your consideration!!!
Hello again!
Thank you again for your wonderful project.
There is another very cool library
universe
, perhaps you're already aware of it, but briefly it is a library "for types where we know all the values". And I think it would be great to add instances of theUniverse
andFinite
(Finite universes) classes for the data types in thesmash
library. I initially tried to add instances directly to theuniverse
package, see dmwit/universe#62 but it was reasonably suggested that I should try to add the instances here first. The implementations are straight forward:And in the event the
These
type becomes available (either through this package or directly from thethese
package [I'll be opening a ticket there next]),toCan
ideally would instead be written:Here's some example usage in GHCi:
The
cardinality
feature is particularly awesome because it allows one to compute the cardinality efficiently using simple arithmetic instead of using the default definition which would expand the entire universe (i.e. create a list of all the values) and then have to take the length of said list.I'm not sure if you're interested in adding these instances, I won't be offended if you aren't but I figure it is worth asking. Have a great day!
The text was updated successfully, but these errors were encountered: