Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the same Empty returned when it matched in a function?

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?

like image 678
raam86 Avatar asked Feb 07 '17 19:02

raam86


People also ask

What does the match function return?

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.

Which rule is returned by the rule match function?

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.

Does match return column or row?

=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.

What does the match function return if the lookup value is found in the table?

The MATCH function returns the relative position of the lookup value in the array, not the value itself.


2 Answers

There is nothing in Haskell that lets you observe whether the two Emptys 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.

like image 101
Daniel Wagner Avatar answered Nov 15 '22 08:11

Daniel Wagner


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.

like image 27
trevor cook Avatar answered Nov 15 '22 07:11

trevor cook