Given these F# type declarations...

type Message = | MessageA | MessageB | MessageC | MessageD type State = { Name:string NextStateMap: Map<Message,State> }

...is there an equally expressive definition of this specific state machine...

let rec state0 = { Name = "0"; NextStateMap = Map.ofList [ (MessageA,state1); (MessageB,state2)] } and state1 = { Name = "1"; NextStateMap = Map.ofList [ (MessageB,state3)] } and state2 = { Name = "2"; NextStateMap = Map.ofList [ (MessageA,state3)] } and state3 = { Name = "3"; NextStateMap = Map.ofList [ (MessageC,state4)] } and state4 = { Name = "4"; NextStateMap = Map.ofList [ (MessageD,state5)] } and state5 = { Name = "5"; NextStateMap = Map.empty}

...with Python?

Note that via the "rec", we didn't have to do assignments in an order defined by a topological sort... (e.g. state0 is defined in terms of state1, even though state1 is defined later on).

P.S. The option of using strings as state identifiers...

stateMachine = { "0" : { "A":"1", "B":"2"}, "1" : { "B":"3" }, ...

...leaves open the case of invalid keys (i.e. invalid message specifiers in the state machine).