we have mapOptional from the NICTA course:
mapOptional :: (a -> b) -> Optional a -> Optional b
mapOptional _ Empty = Empty
mapOptional f (Full a) = Full (f a)
When matching f
we obviously use that function that was passed, what about the Empty
? and what about Full
?
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.
RULE-MATCH – function returns the first rule in the set of rules that matches the given state description. RULE-ACTION – the selected rule is executed as action of the given percept.
=MATCH() returns the position of a cell in a row or column. Combined, the two formulas can look up and return the value of a cell in a table based on vertical and horizontal criteria.
The MATCH function returns the relative position of the lookup value in the array, not the value itself.
There is nothing in Haskell that lets you observe whether the two Empty
s are the same Empty
or not, and no guarantees about what an implementation must do with that code in that regard.
That said, in GHC, nullary constructors for a given parameterized type are shared across all parameterizations; so there is just one Empty
in the whole program, and just one []
, and so forth.
They can't be the same Empty, the argument has the type Optional a
and the output has the type Optional b
. When I try to force some sort of reuse, I will typically use something of the type
mapOptional _ a@Empty = a
This won't compile, and I don't think that's implementation dependent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With