module DynListF(dynF, DynFMsg(..), dynListF) where
import Command
import FRequest
--import Xtypes
import CompOps((>^=<),(>=^^<))
import CompSP
import Dynforkmerge
import Fudget
--import Message(Message(..))
import NullF
import Spops
import Direction
import Path
import LayoutRequest

type DynFMsg a b = DynMsg a (F a b)

dynListF :: F (Int, DynFMsg a b) (Int, b)
dynListF :: F (Int, DynFMsg a b) (Int, b)
dynListF =
    let prep :: Message ([Direction], b) (Int, DynMsg b (F hi ho))
-> [Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
prep (High (Int
t, DynMsg b
m)) = [(Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
-> Message
     ([Direction], FRequest)
     (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
forall a b. b -> Message a b
High (Int
t, Message ([Direction], b) b
-> DynMsg (Message ([Direction], b) b) (FSP hi ho)
forall a b. a -> DynMsg a b
DynMsg (b -> Message ([Direction], b) b
forall a b. b -> Message a b
High b
m))]
        prep (High (Int
t, DynMsg b (F hi ho)
DynDestroy)) = 
	    (FRequest
 -> Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho)))
-> [FRequest]
-> [Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
forall a b. (a -> b) -> [a] -> [b]
map FRequest
-> Message
     ([Direction], FRequest)
     (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
forall b b. b -> Message ([Direction], b) b
tag [XCommand -> FRequest
XCmd XCommand
DestroyWindow,LayoutMessage -> FRequest
LCmd LayoutMessage
LayoutDestroy] 
		[Message
   ([Direction], FRequest)
   (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
-> [Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
-> [Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
forall a. [a] -> [a] -> [a]
++ [(Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
-> Message
     ([Direction], FRequest)
     (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
forall a b. b -> Message a b
High (Int
t, DynMsg (Message ([Direction], b) b) (FSP hi ho)
forall a b. DynMsg a b
DynDestroy)] 
	    where tag :: b -> Message ([Direction], b) b
tag b
m = ([Direction], b) -> Message ([Direction], b) b
forall a b. a -> Message a b
Low (Direction -> [Direction] -> [Direction]
turn (Int -> Direction
Dno Int
t) [Direction]
here, b
m)
        prep (High (Int
t, DynCreate (F FSP hi ho
f))) = [(Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
-> Message
     ([Direction], FRequest)
     (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
forall a b. b -> Message a b
High (Int
t, FSP hi ho -> DynMsg (Message ([Direction], b) b) (FSP hi ho)
forall a b. b -> DynMsg a b
DynCreate FSP hi ho
f)]
        prep (Low ([], b
ev)) = []
        prep (Low ([Direction]
tag, b
ev)) =
            case [Direction] -> (Direction, [Direction])
path [Direction]
tag of
              (Dno Int
i, [Direction]
tag') -> [(Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
-> Message
     ([Direction], FRequest)
     (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))
forall a b. b -> Message a b
High (Int
i, Message ([Direction], b) b
-> DynMsg (Message ([Direction], b) b) (FSP hi ho)
forall a b. a -> DynMsg a b
DynMsg (([Direction], b) -> Message ([Direction], b) b
forall a b. a -> Message a b
Low ([Direction]
tag', b
ev)))]
	      (Direction, [Direction])
_ -> [] -- wrong address!
        post :: Message ([Direction], b) (Int, Message ([Direction], b) b)
-> Message ([Direction], b) (Int, b)
post (High (Int
t, High b
m)) = (Int, b) -> Message ([Direction], b) (Int, b)
forall a b. b -> Message a b
High (Int
t, b
m)
        post (High (Int
i, Low ([Direction]
tag, b
cmd))) = ([Direction], b) -> Message ([Direction], b) (Int, b)
forall a b. a -> Message a b
Low (Direction -> [Direction] -> [Direction]
turn (Int -> Direction
Dno Int
i) [Direction]
tag, b
cmd)
        post (Low ([Direction], b)
c) = ([Direction], b) -> Message ([Direction], b) (Int, b)
forall a b. a -> Message a b
Low ([Direction], b)
c
    in FSP (Int, DynFMsg a b) (Int, b) -> F (Int, DynFMsg a b) (Int, b)
forall hi ho. FSP hi ho -> F hi ho
F{-ff-} (FSP (Int, DynFMsg a b) (Int, b) -> F (Int, DynFMsg a b) (Int, b))
-> FSP (Int, DynFMsg a b) (Int, b) -> F (Int, DynFMsg a b) (Int, b)
forall a b. (a -> b) -> a -> b
$ SP
  (Message
     ([Direction], FRequest)
     (Int,
      DynSPMsg
        (Message ([Direction], FResponse) a)
        (Message ([Direction], FRequest) b)))
  (Message ([Direction], FRequest) (Int, b))
-> SP
     (Message ([Direction], FResponse) (Int, DynFMsg a b))
     (Message
        ([Direction], FRequest)
        (Int,
         DynSPMsg
           (Message ([Direction], FResponse) a)
           (Message ([Direction], FRequest) b)))
-> FSP (Int, DynFMsg a b) (Int, b)
forall a1 b a2. SP a1 b -> SP a2 a1 -> SP a2 b
serCompSP ((Message
   ([Direction], FRequest) (Int, Message ([Direction], FRequest) b)
 -> Message ([Direction], FRequest) (Int, b))
-> SP
     (Message
        ([Direction], FRequest)
        (Int,
         DynSPMsg
           (Message ([Direction], FResponse) a)
           (Message ([Direction], FRequest) b)))
     (Message
        ([Direction], FRequest) (Int, Message ([Direction], FRequest) b))
-> SP
     (Message
        ([Direction], FRequest)
        (Int,
         DynSPMsg
           (Message ([Direction], FResponse) a)
           (Message ([Direction], FRequest) b)))
     (Message ([Direction], FRequest) (Int, b))
forall t b a. (t -> b) -> SP a t -> SP a b
postMapSP Message
  ([Direction], FRequest) (Int, Message ([Direction], FRequest) b)
-> Message ([Direction], FRequest) (Int, b)
forall b b.
Message ([Direction], b) (Int, Message ([Direction], b) b)
-> Message ([Direction], b) (Int, b)
post (SP
  (Int,
   DynSPMsg
     (Message ([Direction], FResponse) a)
     (Message ([Direction], FRequest) b))
  (Int, Message ([Direction], FRequest) b)
-> SP
     (Message
        ([Direction], FRequest)
        (Int,
         DynSPMsg
           (Message ([Direction], FResponse) a)
           (Message ([Direction], FRequest) b)))
     (Message
        ([Direction], FRequest) (Int, Message ([Direction], FRequest) b))
forall a1 b a2. SP a1 b -> SP (Message a2 a1) (Message a2 b)
idLowSP SP
  (Int,
   DynSPMsg
     (Message ([Direction], FResponse) a)
     (Message ([Direction], FRequest) b))
  (Int, Message ([Direction], FRequest) b)
forall a b c. Eq a => SP (a, DynSPMsg b c) (a, c)
dynforkmerge)) ((Message ([Direction], FResponse) (Int, DynFMsg a b)
 -> [Message
       ([Direction], FRequest)
       (Int,
        DynSPMsg
          (Message ([Direction], FResponse) a)
          (Message ([Direction], FRequest) b))])
-> SP
     (Message ([Direction], FResponse) (Int, DynFMsg a b))
     (Message
        ([Direction], FRequest)
        (Int,
         DynSPMsg
           (Message ([Direction], FResponse) a)
           (Message ([Direction], FRequest) b)))
forall t b. (t -> [b]) -> SP t b
concmapSP Message ([Direction], FResponse) (Int, DynFMsg a b)
-> [Message
      ([Direction], FRequest)
      (Int,
       DynSPMsg
         (Message ([Direction], FResponse) a)
         (Message ([Direction], FRequest) b))]
forall b b hi ho.
Message ([Direction], b) (Int, DynMsg b (F hi ho))
-> [Message
      ([Direction], FRequest)
      (Int, DynMsg (Message ([Direction], b) b) (FSP hi ho))]
prep)

dynF :: (F a b) -> F (Either (F a b) a) b
dynF :: F a b -> F (Either (F a b) a) b
dynF F a b
f0 =
    let prep :: Either b a -> [(a, DynMsg a b)]
prep (Left b
f) = [(a
0, DynMsg a b
forall a b. DynMsg a b
DynDestroy), (a
0, b -> DynMsg a b
forall a b. b -> DynMsg a b
DynCreate b
f)]
        prep (Right a
m) = [(a
0, a -> DynMsg a b
forall a b. a -> DynMsg a b
DynMsg a
m)]
    in ((Int, b) -> b
forall a b. (a, b) -> b
snd ((Int, b) -> b)
-> F (Int, DynMsg a (F a b)) (Int, b)
-> F (Int, DynMsg a (F a b)) b
forall a b e. (a -> b) -> F e a -> F e b
>^=< [(Int, DynMsg a (F a b))]
-> F (Int, DynMsg a (F a b)) (Int, b)
-> F (Int, DynMsg a (F a b)) (Int, b)
forall hi ho. [hi] -> F hi ho -> F hi ho
startupF [(Int
0, F a b -> DynMsg a (F a b)
forall a b. b -> DynMsg a b
DynCreate F a b
f0)] F (Int, DynMsg a (F a b)) (Int, b)
forall a b. F (Int, DynFMsg a b) (Int, b)
dynListF) F (Int, DynMsg a (F a b)) b
-> SP (Either (F a b) a) (Int, DynMsg a (F a b))
-> F (Either (F a b) a) b
forall c d e. F c d -> SP e c -> F e d
>=^^< (Either (F a b) a -> [(Int, DynMsg a (F a b))])
-> SP (Either (F a b) a) (Int, DynMsg a (F a b))
forall t b. (t -> [b]) -> SP t b
concmapSP Either (F a b) a -> [(Int, DynMsg a (F a b))]
forall a b a. Num a => Either b a -> [(a, DynMsg a b)]
prep