[2016-03-28] Challenge #260 [Easy] Garage Door Opener

F# - A little late, but I'd prefer to do an easy challenge while figuring out how F# works.

type GarageStatus = | Open | Closed | Opening | Closing | StoppedClosing | StoppedOpening

let ClickButton gs =
    match gs with
    | Open ->  GarageStatus.Closing
    | Opening ->   GarageStatus.StoppedOpening
    | Closed->   GarageStatus.Opening
    | Closing ->   GarageStatus.StoppedClosing
    | StoppedClosing ->  GarageStatus.Opening
    | StoppedOpening ->  GarageStatus.Closing

let FinishCycle gs = 
    match gs with
    | Opening ->  GarageStatus.Open
    | Closing ->  GarageStatus.Closed

let InputGarageCommand gs cmd = 
    match cmd with
    | "button_clicked" -> ClickButton gs
    | "cycle_complete" -> FinishCycle  gs

let printGarageStatus gs =
    match gs with
    | Open -> printfn "Door: OPEN"
    | Opening -> printfn "Door: OPENING"
    | Closed-> printfn "Door: CLOSED"
    | Closing -> printfn "Door: CLOSING"
    | StoppedClosing -> printfn "Door: STOPPED_WHILE_CLOSING"
    | StoppedOpening -> printfn "Door: STOPPED_WHILE_OPENING"

let printGarageCommand (c:string) = 
    match c with
    |"button_clicked" -> printfn "> Button clicked."
    |"cycle_complete" -> printfn "> Cycle complete."

let handleCommands list gs =
        let rec loop cmds gs =
            match cmds with
            |[] -> null
            | head::tail -> 
                printGarageCommand head
                let ns = InputGarageCommand gs head
                printGarageStatus ns
                loop tail ns
        printGarageStatus gs
        loop list gs

let commands = ["button_clicked"; "cycle_complete"; "button_clicked"; "button_clicked"; "button_clicked"; "button_clicked"; "button_clicked"; "cycle_complete"; ] 
handleCommands commands GarageStatus.Closed  
/r/dailyprogrammer Thread