In Idris, the Maybe
type is defined as followed:
data Maybe a = Just a | Nothing
It\'s defined similarly in Haskell:
Consider this somewhat equivalent of Maybe in C++/Java'ish psuedocode...
template
abstract class Maybe { ... }
template
class Just : Maybe {
// constructor
Just (T val) { ... }
...
}
template
class Nothing : Maybe {
// constructor
Nothing () { ... }
...
}
That is not specific to Maybe, it can be applied to any ADT. Now what exactly will
data Maybe a = a | Nothing
model into ? (assuming that its legal syntax).
If you were to write a switch statement, to 'pattern match' against types, what will u match against (the switch is on the TYPE not the value), something like this (not necessarily valid code) :
switch (typeof (x)) {
case Just : ...
case Nothing : ...
default : ... // Here you dont have any 'a' to get the inner type
}