0

Is is possible when you call, say, mapName(identifier), it returns something that is not 'rangeType option', given that it's a finite map (finite domain and range) and you are sure that the identifier exists in the map?

chris
  • 4,988
  • 20
  • 36
MooMooCoding
  • 319
  • 1
  • 5
  • 15
  • 1
    If you have a map `map_name` of type `'a => 'b option` and know that `map_name id` will result in `Some x` for some `x` of type `'b`, then you can use `the :: 'a option => 'a` to extract `x` immediately, i.e., `the (map_name x)` will result in `x`. – chris Dec 17 '15 at 11:53
  • That's exactly what I need. Thank you, Chris! – MooMooCoding Dec 17 '15 at 19:14
  • Okay, then I'll turn my comment into an answer, so that this question can be marked as answered for later visitors. – chris Dec 18 '15 at 09:33

1 Answers1

0

Before answering your question, let us make the kind of "partial functions" we are talking about precise.

(Explicitly) partial functions have type 'a => 'b option in Isabelle/HOL. Then for every given x :: 'a such a partial function f :: 'a => 'b option results either in None (meaning that f is not defined on x) or Some y :: 'b option (whenever f actually is defined on x).

Now, if for some input x you know (which in Isabelle/HOL should mean that you have a proof for it) that f x is defined, you can employ the selector-function the : 'a option => 'a of the option type. So whenever f x = Some y then the (f x) results in y.

Note that in principle it is also possible to call the None. In that case we encounter a different kind of partial function that is available in Isabelle/HOL. The result of the None will still be of type 'b but it is some arbitrary (and thus "undefined") value of that type 'b of which we can prove virtually nothing.

chris
  • 4,988
  • 20
  • 36