3 ms·
In Haskell, you can have conditionals/pattern matching on a parameter's type, in the range of the declared types. For example, if you have a parameter of type `
by simiones 5y ago
In Haskell, you can have conditionals/pattern matching on a parameter's type, in the range of the declared types. For example, if you have a parameter of type `Int | Char`, you can pattern match to see if it's Int or Char. But if it's type is completely unbound, you can't do anything with it except pass it around.
There is support for reflection, but you have to explicitly ask for it, using Typeable or Data as far as I understand. That is, your function signature still has to constrain the type parameter to be an instance of Typeable or Data (a "reflectable type").
- eru 5y agoExactly! Thanks for saving me the explanation. And almost any type you care about is an instance of Typeable or Data. And your own types can get those instances for free from the compiler, if you ask for them.