
Hi, I have a function Delta and two sets S and A. Delta maps some elements from (S x A) to S. How can I extend Delta to some Delta' such that it assigns to every pair in (S x A) that Delta is not defined for a value not occuring in S? Something like: Delta' = if (Delta s a) /= _Undefined_ then Delta s a else if () n where n is the new value. However Delta' should not assign values to pairs not in (S x A). Note: (S x A) is meant to be the set-crossprroduct. Background: I want to learn Haskell by building a small library for Finite State Automata, Büchi Automata etc. I need this extension of Delta for making automata complete. Regards and thanks for reading, Heinrich

On Fri, Feb 22, 2013 at 06:35:19PM +0100, Heinrich Ody wrote:
Hi,
I have a function Delta and two sets S and A. Delta maps some elements from (S x A) to S. How can I extend Delta to some Delta' such that it assigns to every pair in (S x A) that Delta is not defined for a value not occuring in S?
If your function delta is partial, then you should model this in Haskell by having it return a Maybe, i.e. delta :: S -> Maybe A Then you can define delta' like this: delta' s a = case delta s a of Nothing -> n Just x -> x If your function delta really is partial in Haskell (i.e. it sometimes crashes or returns 'undefined') then you cannot implement delta', because there is no way to check whether a function returns undefined. It is not a good idea to have partial functions in Haskell anyway. -Brent
participants (2)
-
Brent Yorgey
-
Heinrich Ody