Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev websocket machine learning #32

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@

* Check cabal outdated
* Check in diffs between solution and problem and make sure it is stable (such that every fix in a solution gets propagated to the problem and vice versa)

## UI

* square that rotates with time
* paint, clear, paintAll: Maybe more complicated program with several paint calls, picture builds up if you forget to call clear
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
test-show-details: direct
packages: rhine-koans.cabal
../rhine/rhine-gloss/rhine-gloss.cabal
../rhine/rhine/rhine.cabal
../rhine/automaton/automaton.cabal
34 changes: 34 additions & 0 deletions generic/test-gloss/TestGloss.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module TestGloss where

-- base
import Control.Concurrent
import Control.Monad
import Data.IORef
import System.Exit

-- rhine-gloss
import FRP.Rhine.Gloss

expectPic :: Picture -> [Picture] -> IO ()
expectPic received expected =
let flattened = flattenPictures received
in if flattened == expected
then putStrLn "Well done!"
else do
putStrLn $ "Expected: " ++ show expected
putStrLn $ "Received: " ++ show flattened
exitFailure

flattenPictures :: Picture -> [Picture]
flattenPictures (Pictures ps) = ps >>= flattenPictures
flattenPictures Blank = []
flattenPictures picture = [picture]

stepGlossRhine :: Rhine (GlossConcT IO) GlossSimClockIO () () -> [Float] -> IO [Picture]
stepGlossRhine rhine timestamps = do
vars <- makeGlossEnv
void $ forkIO $ runGlossConcT (flow rhine) vars
forM timestamps $ \timestamp -> do
putMVar (timeVar vars) timestamp
threadDelay 100000
readIORef (picRef vars)
256 changes: 256 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
cradle:
cabal:
- path: "generic/test-io"
component: "rhine-koans:lib:test-io"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-1-hello-rhine"

- path: "koans/basic/1/1-hello-rhine/test"
component: "rhine-koans:test:basic-1-1-hello-rhine-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-2-fix-the-bug"

- path: "koans/basic/1/2-fix-the-bug/test"
component: "rhine-koans:test:basic-1-2-fix-the-bug-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-3-faster"

- path: "koans/basic/1/3-faster/test"
component: "rhine-koans:test:basic-1-3-faster-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-4-compose"

- path: "koans/basic/1/4-compose/test"
component: "rhine-koans:test:basic-1-4-compose-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-5-compose-more"

- path: "koans/basic/1/5-compose-more/test"
component: "rhine-koans:test:basic-1-5-compose-more-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-6-compose-signal-functions-and-clocks"

- path: "koans/basic/1/6-compose-signal-functions-and-clocks/test"
component: "rhine-koans:test:basic-1-6-compose-signal-functions-and-clocks-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-7-compose-on-the-same-clock"

- path: "koans/basic/1/7-compose-on-the-same-clock/test"
component: "rhine-koans:test:basic-1-7-compose-on-the-same-clock-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-1-8-compose-on-different-clocks"

- path: "koans/basic/1/8-compose-on-different-clocks/test"
component: "rhine-koans:test:basic-1-8-compose-on-different-clocks-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-1-input"

- path: "koans/basic/2/1-input/test"
component: "rhine-koans:test:basic-2-1-input-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-2-count-the-words"

- path: "koans/basic/2/2-count-the-words/test"
component: "rhine-koans:test:basic-2-2-count-the-words-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-3-count-the-lines"

- path: "koans/basic/2/3-count-the-lines/test"
component: "rhine-koans:test:basic-2-3-count-the-lines-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-4-count-all-the-words"

- path: "koans/basic/2/4-count-all-the-words/test"
component: "rhine-koans:test:basic-2-4-count-all-the-words-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-5-count-all-the-chars"

- path: "koans/basic/2/5-count-all-the-chars/test"
component: "rhine-koans:test:basic-2-5-count-all-the-chars-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-6-count-everything"

- path: "koans/basic/2/6-count-everything/test"
component: "rhine-koans:test:basic-2-6-count-everything-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-7-count-everything-nicer"

- path: "koans/basic/2/7-count-everything-nicer/test"
component: "rhine-koans:test:basic-2-7-count-everything-nicer-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-8-dont-count-everything"

- path: "koans/basic/2/8-dont-count-everything/test"
component: "rhine-koans:test:basic-2-8-dont-count-everything-test"

- path: "./Main.hs"
component: "rhine-koans:exe:basic-2-9-modularize"

- path: "koans/basic/2/9-modularize/test"
component: "rhine-koans:test:basic-2-9-modularize-test"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-1-circle"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-1-circle-test"

- path: "koans/ui/1-gloss/1-circle/test"
component: "rhine-koans:test:ui-1-gloss-1-circle-test"

- path: "koans/ui/1-gloss/1-circle"
component: "rhine-koans:test:ui-1-gloss-1-circle-test"

- path: "koans/ui/1-gloss/1-circle/solution"
component: "rhine-koans:test:ui-1-gloss-1-circle-test"

- path: "koans/ui/1-gloss/1-circle"
component: "rhine-koans:exe:ui-1-gloss-1-circle"

- path: "koans/ui/1-gloss/1-circle/solution"
component: "rhine-koans:exe:ui-1-gloss-1-circle"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-2-move"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-2-move-test"

- path: "koans/ui/1-gloss/2-move/test"
component: "rhine-koans:test:ui-1-gloss-2-move-test"

- path: "koans/ui/1-gloss/2-move"
component: "rhine-koans:test:ui-1-gloss-2-move-test"

- path: "koans/ui/1-gloss/2-move/solution"
component: "rhine-koans:test:ui-1-gloss-2-move-test"

- path: "koans/ui/1-gloss/2-move"
component: "rhine-koans:exe:ui-1-gloss-2-move"

- path: "koans/ui/1-gloss/2-move/solution"
component: "rhine-koans:exe:ui-1-gloss-2-move"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-3-modularize"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-3-modularize-test"

- path: "koans/ui/1-gloss/3-modularize/test"
component: "rhine-koans:test:ui-1-gloss-3-modularize-test"

- path: "koans/ui/1-gloss/3-modularize"
component: "rhine-koans:test:ui-1-gloss-3-modularize-test"

- path: "koans/ui/1-gloss/3-modularize/solution"
component: "rhine-koans:test:ui-1-gloss-3-modularize-test"

- path: "koans/ui/1-gloss/3-modularize"
component: "rhine-koans:exe:ui-1-gloss-3-modularize"

- path: "koans/ui/1-gloss/3-modularize/solution"
component: "rhine-koans:exe:ui-1-gloss-3-modularize"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-4-user-input"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-4-user-input-test"

- path: "koans/ui/1-gloss/4-user-input/test"
component: "rhine-koans:test:ui-1-gloss-4-user-input-test"

- path: "koans/ui/1-gloss/4-user-input"
component: "rhine-koans:test:ui-1-gloss-4-user-input-test"

- path: "koans/ui/1-gloss/4-user-input/solution"
component: "rhine-koans:test:ui-1-gloss-4-user-input-test"

- path: "koans/ui/1-gloss/4-user-input"
component: "rhine-koans:exe:ui-1-gloss-4-user-input"

- path: "koans/ui/1-gloss/4-user-input/solution"
component: "rhine-koans:exe:ui-1-gloss-4-user-input"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-5-randomness"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-5-randomness-test"

- path: "koans/ui/1-gloss/5-randomness/test"
component: "rhine-koans:test:ui-1-gloss-5-randomness-test"

- path: "koans/ui/1-gloss/5-randomness"
component: "rhine-koans:test:ui-1-gloss-5-randomness-test"

- path: "koans/ui/1-gloss/5-randomness/solution"
component: "rhine-koans:test:ui-1-gloss-5-randomness-test"

- path: "koans/ui/1-gloss/5-randomness"
component: "rhine-koans:exe:ui-1-gloss-5-randomness"

- path: "koans/ui/1-gloss/5-randomness/solution"
component: "rhine-koans:exe:ui-1-gloss-5-randomness"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-6-control-flow"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-6-control-flow-test"

- path: "koans/ui/1-gloss/6-control-flow/test"
component: "rhine-koans:test:ui-1-gloss-6-control-flow-test"

- path: "koans/ui/1-gloss/6-control-flow"
component: "rhine-koans:test:ui-1-gloss-6-control-flow-test"

- path: "koans/ui/1-gloss/6-control-flow/solution"
component: "rhine-koans:test:ui-1-gloss-6-control-flow-test"

- path: "koans/ui/1-gloss/6-control-flow"
component: "rhine-koans:exe:ui-1-gloss-6-control-flow"

- path: "koans/ui/1-gloss/6-control-flow/solution"
component: "rhine-koans:exe:ui-1-gloss-6-control-flow"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:exe:ui-1-gloss-snake"

- path: "generic/reimport-main/Main.hs"
component: "rhine-koans:test:ui-1-gloss-snake-test"

- path: "koans/ui/1-gloss/snake/test"
component: "rhine-koans:test:ui-1-gloss-snake-test"

- path: "koans/ui/1-gloss/snake"
component: "rhine-koans:test:ui-1-gloss-snake-test"

- path: "koans/ui/1-gloss/snake/solution"
component: "rhine-koans:test:ui-1-gloss-snake-test"

- path: "koans/ui/1-gloss/snake"
component: "rhine-koans:exe:ui-1-gloss-snake"

- path: "koans/ui/1-gloss/snake/solution"
component: "rhine-koans:exe:ui-1-gloss-snake"

- path: "koans/wsml"
component: "rhine-koans:exe:wsml"
41 changes: 41 additions & 0 deletions koans/ui/1-gloss/1-circle/Koan.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{- | Circle.

Let's draw something!
Rhine connects to the famous gloss library for 2d graphics.
Have a look at https://hackage.haskell.org/package/gloss to learn more about it!

The connection between Rhine and gloss is provided by the library https://hackage.haskell.org/package/rhine-gloss,
which encapsulates the effects of drawing pictures in gloss in a monad, 'GlossConcT',
and provides several clocks to interact with the gloss system.

To warm up, let's just draw a circle.
-}
module Koan where

-- rhine
import FRP.Rhine

-- rhine-gloss
import FRP.Rhine.Gloss

{- | The main 'Rhine' of this program.

/--- We use effects in 'GlossConcT' to draw images.
|
| /--- This clock ticks whenever an image is drawn on the screen by the gloss backend.
| |
v v
-}
rhine :: Rhine (GlossConcT IO) GlossSimClockIO () ()
-- Can you create a solid circle of radius 10 here?
-- Have a look at https://hackage.haskell.org/package/gloss/docs/Graphics-Gloss-Data-Picture.html for inspiration.
rhine =
constMCl (paintAllIO _) -- paintAllIO clears the drawing canvas and draws the given image
@@ GlossSimClockIO -- The singleton value of GlossSimClockIO.

main :: IO ()
-- Make sure to keep this definition here as it is: The tests depend on it.
main =
flowGlossIO -- This function can replace 'flow' when you're using the gloss backend.
defaultSettings -- Settings for the gloss window context such as size, title, and background colour.
rhine
41 changes: 41 additions & 0 deletions koans/ui/1-gloss/1-circle/solution/Koan.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{- | Circle.

Let's draw something!
Rhine connects to the famous gloss library for 2d graphics.
Have a look at https://hackage.haskell.org/package/gloss to learn more about it!

The connection between Rhine and gloss is provided by the library https://hackage.haskell.org/package/rhine-gloss,
which encapsulates the effects of drawing pictures in gloss in a monad, 'GlossConcT',
and provides several clocks to interact with the gloss system.

To warm up, let's just draw a circle.
-}
module Koan where

-- rhine
import FRP.Rhine

-- rhine-gloss
import FRP.Rhine.Gloss

{- | The main 'Rhine' of this program.

/--- We use effects in 'GlossConcT' to draw images.
|
| /--- This clock ticks whenever an image is drawn on the screen by the gloss backend.
| |
v v
-}
rhine :: Rhine (GlossConcT IO) GlossSimClockIO () ()
-- Can you create a solid circle of radius 10 here?
-- Have a look at https://hackage.haskell.org/package/gloss/docs/Graphics-Gloss-Data-Picture.html for inspiration.
rhine =
constMCl (paintAllIO (circleSolid 10)) -- paintAllIO clears the drawing canvas and draws the given image
@@ GlossSimClockIO -- The singleton value of GlossSimClockIO.

main :: IO ()
-- Make sure to keep this definition here as it is: The tests depend on it.
main =
flowGlossIO -- This function can replace 'flow' when you're using the gloss backend.
defaultSettings -- Settings for the gloss window context such as size, title, and background colour.
rhine
Loading
Loading