Is the same Empty true when it corresponds to a function?

we have mapOptional from the NICTA course:

mapOptional :: (a -> b) -> Optional a -> Optional b mapOptional _ Empty = Empty mapOptional f (Full a) = Full (fa) 

When matching f we obviously use this function, which was passed, how about Empty ? and how about Full ?

+5
source share
2 answers

There is nothing in Haskell that allows you to observe whether the two Empty same Empty or not, and there is no guarantee what the implementation should do with this code in this regard.

Thus, in the GHC, constructors with a zero value for a given parameterized type are divided into all parameterizations; therefore, in the entire program there is only one Empty and only one [] , etc.

+7
source

They cannot be the same. Empty, the argument is of type Optional a , and the output is of type Optional b . When I try to use some kind of reuse, I usually use something like

 mapOptional _ a@Empty = a 

This does not compile, and I do not think it depends on the implementation.

+2
source

Source: https://habr.com/ru/post/1263934/


All Articles