Skip to content

Commit

Permalink
Solve koans
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Jan 3, 2024
1 parent e6fd097 commit 2c52885
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion koans/basic/1-hello-rhine/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ everySecond = waitClock -- A particular implementation of this clock that waits
message :: ClSF IO (Millisecond 1000) () ()
message =
constMCl -- Perform the following side effect every time the clock ticks.
(putStrLn _) -- This is the side effect to perform. Insert your message in the hole!
(putStrLn "Hello Rhine!") -- This is the side effect to perform. Insert your message in the hole!

main :: IO ()
main =
Expand Down
2 changes: 1 addition & 1 deletion koans/basic/2-fix-the-bug/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Koan where
import FRP.Rhine

-- | A clock that ticks every second.
everySecond :: Millisecond 2345
everySecond :: Millisecond 1000
everySecond = waitClock

-- | A component of the whole signal network.
Expand Down
6 changes: 2 additions & 4 deletions koans/basic/3-faster/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ module Koan where
import FRP.Rhine

-- Can you complete this?

{- | The clock _type_ specifies the rate of the clock.
type TenPerSecond = Millisecond _
-}
-- | The clock _type_ specifies the rate of the clock.
type TenPerSecond = Millisecond 100

-- | A clock that ticks 10 times second.
tenPerSecond :: TenPerSecond
Expand Down
2 changes: 1 addition & 1 deletion koans/basic/4-compose/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ printMessage =
mainComponent :: ClSF IO EverySecond () ()
-- Can you fill in the two components from above,
-- one to the right and one to the left of the composition operator?
mainComponent = _ >-> _
mainComponent = produceMessage >-> printMessage

main :: IO ()
main = flow $ mainComponent @@ everySecond
2 changes: 1 addition & 1 deletion koans/basic/5-compose-more/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ printMessage = arrMCl Text.putStrLn
mainComponent :: ClSF IO EverySecond () ()
-- Can you fill in the _three_ components from above,
-- in the order sensor, function, actuator?
mainComponent = _ >>> _ >>> _
mainComponent = produceMessage >>> exclamate >>> printMessage

-- Huh, it seems we can often use >>> instead of >-> as well!

Expand Down
2 changes: 1 addition & 1 deletion koans/basic/6-compose-signal-functions-and-clocks/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ printMessage = arrMCl Text.putStrLn
-}
mainRhine :: Rhine IO EverySecond () ()
-- The operators >>> and @@ don't combine well. Try brackets, or the >-> operator!
mainRhine = produceMessage >>> exclamate >>> printMessage @@ everySecond
mainRhine = produceMessage >-> exclamate >-> printMessage @@ everySecond

main :: IO ()
main =
Expand Down
6 changes: 3 additions & 3 deletions koans/basic/7-compose-on-the-same-clock/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ everySecond :: EverySecond
everySecond = waitClock

-- | Produce an incomplete message.
produceMessage :: ClSF IO (Millisecond 2345) () Text
produceMessage :: ClSF IO EverySecond () Text
produceMessage = arr $ const "Hello Rhine"

-- | Add an exclamation mark ("!") to a Text.
exclamate :: (Monad m) => ClSF m (Millisecond 3456) Text Text
exclamate :: (Monad m) => ClSF m EverySecond Text Text
exclamate = arr (<> "!")

-- | Outputs a message every second.
printMessage :: ClSF IO (Millisecond 4567) Text ()
printMessage :: ClSF IO EverySecond Text ()
printMessage = arrMCl Text.putStrLn

-- | A complete Rhine program that prints "Hello Rhine!" every second.
Expand Down
2 changes: 1 addition & 1 deletion koans/basic/8-compose-on-different-clocks/Koan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ and a resampling buffer in the middle.
Can you fill the gap?
-}
mainRhine :: Rhine IO MainClock () ()
mainRhine = produceRhine >-- _ --> printRhine
mainRhine = produceRhine >-- fiveToOne --> printRhine

main :: IO ()
main = flow mainRhine

0 comments on commit 2c52885

Please sign in to comment.