Vote count: 0
In Haskell, or any other programming language supporting pattern matching, can we achieve the following:
Given a type constructor e.g. Left :: a -> Either a b
I can extract its argument with
let f (Left x) = [x]
Is there any way to achieve the same thing for any type constructor, something like an operator (*
) to lift Left x
to Apply (λa.Left a) [x]
or BinTree x y
to Apply (λa,b.BinTree a b) [x,y]
, so we could do
let extract x = case *x of Apply _ xs -> xs
asked 33 secs ago
Can we deconstruct arbitrary type constructors?
Aucun commentaire:
Enregistrer un commentaire