by Anderkent · 13y ago · 0 comments
Say something like:
enum Node<A> { StringNode(Node, Node, ~string) IntNode(Node, Node, int) VoidNode(Node, Node) }
Is there any way of declaring that StringNode gives you Node<~string>, and IntNode gives Node<int>?
data T a where
TI :: Int -> T Int
TS :: String -> T String
which lets you reflect a value up into its type. Something similar but more implicit seems to be going on with that Rust example.Another method is kind of a hack: unify the type variable with an unused argument. This looks like
data T a b = T b -- we want to find a way to choose a
setA :: a -> T a b -> T a b
setA _ t = t -- Just returns the second argument
-- BUT tells the compiler the `a` type unifies
-- with the type of the first argument
> :t setA Int (T "foo")
setA Int (T "foo") :: T Int String