From 5c7c1f0323ed2b60f25115bad357b00a2255cd12 Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Fri, 15 Jul 2022 07:55:38 -0500 Subject: [PATCH] Use div-root; fix examples' warnings (#286) * Fix compiler warnings in examples * Add div with 'root' id to support cookbook recipes * Add changelog --- CHANGELOG.md | 2 ++ client/examples/ADTs.purs | 1 + client/examples/DoNotation.purs | 3 ++- client/examples/Generic.purs | 1 + client/examples/Loops.purs | 1 + client/examples/Operators.purs | 1 + client/examples/QuickCheck.purs | 1 + client/examples/Records.purs | 2 ++ client/examples/Recursion.purs | 1 + client/examples/TypeClasses.purs | 1 + client/public/frame.html | 1 + 11 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bc78acb..6bd50ae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ Bugfixes: Other improvements: - Drop requirement that module name be `Main` (#285 by @JordanMartinez) +- Fixes compiler warnings in examples (#286 by @JordanMartinez) +- Support cookbook repo UI recipes by adding element to `frame.html` (#286 by @JordanMartinez) ## [v2022-07-12.1](https://github.com/purescript/trypurescript/releases/tag/v2022-07-12.1) diff --git a/client/examples/ADTs.purs b/client/examples/ADTs.purs index 5bc0dec5..a751c4ca 100644 --- a/client/examples/ADTs.purs +++ b/client/examples/ADTs.purs @@ -19,5 +19,6 @@ derive instance ordName :: Ord Name phoneBook :: Map Name String phoneBook = singleton (Name "John" "Smith") "555-555-1234" +main :: Effect Unit main = render =<< withConsole do logShow (lookup (Name "John" "Smith") phoneBook) diff --git a/client/examples/DoNotation.purs b/client/examples/DoNotation.purs index 98bc3141..512e80cf 100644 --- a/client/examples/DoNotation.purs +++ b/client/examples/DoNotation.purs @@ -5,7 +5,7 @@ import Control.MonadPlus (guard) import Effect.Console (logShow) import Data.Array ((..)) import Data.Foldable (for_) -import TryPureScript +import TryPureScript (render, withConsole) -- Find Pythagorean triples using an array comprehension. triples :: Int -> Array (Array Int) @@ -16,5 +16,6 @@ triples n = do guard $ x * x + y * y == z * z pure [x, y, z] +main :: Effect Unit main = render =<< withConsole do for_ (triples 20) logShow diff --git a/client/examples/Generic.purs b/client/examples/Generic.purs index 1fea8470..e461a772 100644 --- a/client/examples/Generic.purs +++ b/client/examples/Generic.purs @@ -45,6 +45,7 @@ instance eqPerson :: Eq Person where instance ordPerson :: Ord Person where compare = genericCompare +main :: Effect Unit main = render =<< withConsole do logShow $ Person { first: "John" diff --git a/client/examples/Loops.purs b/client/examples/Loops.purs index fc0e1290..bcf907b3 100644 --- a/client/examples/Loops.purs +++ b/client/examples/Loops.purs @@ -7,6 +7,7 @@ import Data.Array ((..)) import Data.Foldable (for_) import TryPureScript (render, withConsole) +main :: Effect Unit main = render =<< withConsole do for_ (10 .. 1) \n -> log (show n <> "...") log "Lift off!" diff --git a/client/examples/Operators.purs b/client/examples/Operators.purs index 23f56351..4b4cba1d 100644 --- a/client/examples/Operators.purs +++ b/client/examples/Operators.purs @@ -16,5 +16,6 @@ infixl 5 subdirectory as filepath :: FilePath filepath = "usr" "local" "bin" +main :: Effect Unit main = render =<< withConsole do log filepath diff --git a/client/examples/QuickCheck.purs b/client/examples/QuickCheck.purs index e513109d..bac5f296 100644 --- a/client/examples/QuickCheck.purs +++ b/client/examples/QuickCheck.purs @@ -5,6 +5,7 @@ import Data.Array (sort) import Test.QuickCheck (quickCheck, (===)) import TryPureScript (render, withConsole, h1, h2, p, text) +main :: Effect Unit main = do render $ h1 $ text "QuickCheck" render $ p $ text """QuickCheck is a Haskell library which allows us to assert properties diff --git a/client/examples/Records.purs b/client/examples/Records.purs index deba7d99..413b4c18 100644 --- a/client/examples/Records.purs +++ b/client/examples/Records.purs @@ -5,10 +5,12 @@ import Effect.Console (log) import TryPureScript (render, withConsole) -- We can write functions which require certain record labels... +showPerson :: forall r. { firstName :: String, lastName :: String | r } -> String showPerson o = o.lastName <> ", " <> o.firstName -- ... but we are free to call those functions with any -- additional arguments, such as "age" here. +main :: Effect Unit main = render =<< withConsole do log $ showPerson { firstName: "John" diff --git a/client/examples/Recursion.purs b/client/examples/Recursion.purs index fd213181..4f3e9396 100644 --- a/client/examples/Recursion.purs +++ b/client/examples/Recursion.purs @@ -12,6 +12,7 @@ isEven :: Int -> Boolean isEven 0 = true isEven n = isOdd (n - 1) +main :: Effect Unit main = render =<< withConsole do logShow $ isEven 1000 logShow $ isEven 1001 diff --git a/client/examples/TypeClasses.purs b/client/examples/TypeClasses.purs index 5853abf6..58a57abf 100644 --- a/client/examples/TypeClasses.purs +++ b/client/examples/TypeClasses.purs @@ -39,6 +39,7 @@ printf = printfWith "" debug :: String -> Int -> String -> String debug uri status msg = printf "[" uri "] " status ": " msg +main :: Effect Unit main = render =<< withConsole do log $ debug "http://www.purescript.org" 200 "OK" log $ debug "http://bad.purescript.org" 404 "Not found" diff --git a/client/public/frame.html b/client/public/frame.html index f40cf9bd..317ecd6e 100644 --- a/client/public/frame.html +++ b/client/public/frame.html @@ -47,5 +47,6 @@
+