{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE Safe #-}--------------------------------------------------------------------------------moduleFSM.Light(Off,On,Transition,off,on,switch)where--------------------------------------------------------------------------------dataOndataOffclassStateawhereclass(Statea,Stateb)=>TransitionabwhereinstanceStateOnwhereinstanceStateOffwhereinstanceTransitionOnOffwhereinstanceTransitionOffOnwhere--------------------------------------------------------------------------------off::Offon::Onswitch::Transitionab=>a->b--------------------------------------------------------------------------------off=undefinedon=undefinedswitch=undefined
#!/usr/bin/envstack{- stack
--resolver lts-12.0
--install-ghc
script
--ghc-options -Werror
--ghc-options -Wall
--
-}--------------------------------------------------------------------------------{-# LANGUAGE Safe #-}--------------------------------------------------------------------------------moduleMain(main)where--------------------------------------------------------------------------------importFSM.Light(Off,On,off,switch)--------------------------------------------------------------------------------blinking::EitherOffOn->EitherOffOnblinking(Leftx)=Right$switchxblinking(Rightx)=Left$switchx{- We can't implement `blinking` incorrectly:
> blinking (Left x) = Left $ switch x
• No instance for (FSM.Light.Transition Off Off)
arising from a use of ‘switch’
-}--------------------------------------------------------------------------------main::IO()main=doputStr"> Type the amount of times to turn on/off the ligth switch: "times<-getLineputStrLn.(++" We turn on/off "++times++" time(s)")$oi$readtimeswheresin=foldl(\a_->blinkinga)(Leftoff)([1..n]::[Integer])oin=casesinofLeft_->"> OFF |"Right_->"> ON |"