Open inthar-raven opened 7 months ago
Adding this to my module fixed it:
import Math.Combinatorics.Species.Structures ((:*:))
-- Utility functions for projecting Hadamard products of species.
pFst :: ((:*:) f g) a -> f a
pFst ((:*:) x y) = x
pSnd :: ((:*:) f g) a -> g a
pSnd ((:*:) x y) = y
pSwap :: ((:*:) f g) a -> ((:*:) g f) a
pSwap ((:*:) x y) = (:*:) y x
It would still be nice if the package exported these functions, though.
Thanks for the report! You're right that there's no reason we can't export pFst
and pSnd
, that was probably just an oversight. (Though really, perhaps we ought to now just re-export Data.Functor.Product
.) But to answer your original question, the way to destructure elements built with :*: is by pattern matching. In my experience, any time I find myself using functions like fst
and snd
, there is usually a cleaner way to write the code by directly pattern-matching on the pair.
I might have missed this part of the documentation, but I can't seem to find a way to destructure elements of my custom species which is a Hadamard product:
where the shape of species
necklaceOfExactArity r
is of typeI can get a list of shapes using
[0..n-1]
as labels with no issue, and each shape should morally be represented as a pair (cycle, list of lists of labels), but I don't know how to access an element of this pair. Is there a reason whyMath.Combinatorics.Species.Structures
doesn't export thepFst
andpSnd
projection functions which should do just that?