tweaks to playground files
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
|
- [ ] add filenames to FC
|
||||||
|
- [ ] add namespaces
|
||||||
- [ ] imported files leak info messages everywhere
|
- [ ] imported files leak info messages everywhere
|
||||||
- For now, take the start ix for the file and report at end starting there
|
- For now, take the start ix for the file and report at end starting there
|
||||||
- [ ] update node shim to include idris2-playground changes
|
- [ ] update node shim to include idris2-playground changes
|
||||||
|
|||||||
@@ -51,20 +51,21 @@ part1 text digits =
|
|||||||
|
|
||||||
#check digits1 ∘ unpack : String -> List Int
|
#check digits1 ∘ unpack : String -> List Int
|
||||||
|
|
||||||
runFile : String -> IO Unit
|
-- readFile not in browser / playground
|
||||||
runFile fn = do
|
|
||||||
text <- readFile fn
|
|
||||||
putStrLn fn
|
|
||||||
putStrLn "part1"
|
|
||||||
putStrLn $ show (part1 text (digits1 ∘ unpack))
|
|
||||||
putStrLn "part2"
|
|
||||||
putStrLn $ show (part1 text (digits2 ∘ unpack))
|
|
||||||
putStrLn ""
|
|
||||||
|
|
||||||
|
-- runFile : String -> IO Unit
|
||||||
|
-- runFile fn = do
|
||||||
|
-- text <- readFile fn
|
||||||
|
-- putStrLn fn
|
||||||
|
-- putStrLn "part1"
|
||||||
|
-- putStrLn $ show (part1 text (digits1 ∘ unpack))
|
||||||
|
-- putStrLn "part2"
|
||||||
|
-- putStrLn $ show (part1 text (digits2 ∘ unpack))
|
||||||
|
-- putStrLn ""
|
||||||
|
|
||||||
-- Argument is a hack to keep it from running at startup. Need to add IO
|
-- -- Argument is a hack to keep it from running at startup. Need to add IO
|
||||||
main : IO Unit
|
-- main : IO Unit
|
||||||
main = do
|
-- main = do
|
||||||
runFile "aoc2023/day1/eg.txt"
|
-- runFile "aoc2023/day1/eg.txt"
|
||||||
runFile "aoc2023/day1/eg2.txt"
|
-- runFile "aoc2023/day1/eg2.txt"
|
||||||
runFile "aoc2023/day1/input.txt"
|
-- runFile "aoc2023/day1/input.txt"
|
||||||
|
|||||||
@@ -82,18 +82,20 @@ part2 (MkGame n parts :: rest) =
|
|||||||
case foldl maxd (0,0,0) parts of
|
case foldl maxd (0,0,0) parts of
|
||||||
(a,b,c) => a * b * c + part2 rest
|
(a,b,c) => a * b * c + part2 rest
|
||||||
|
|
||||||
run : String -> IO Unit
|
-- readFile not in browser / playground
|
||||||
run fn = do
|
|
||||||
text <- readFile fn
|
|
||||||
case mapM parseGame (split (trim text) "\n") of
|
|
||||||
Left err => putStrLn $ "fail " ++ err
|
|
||||||
Right games => do
|
|
||||||
putStrLn "part1"
|
|
||||||
printLn (part1 games)
|
|
||||||
putStrLn "part2"
|
|
||||||
printLn (part2 games)
|
|
||||||
|
|
||||||
main : IO Unit
|
-- run : String -> IO Unit
|
||||||
main = do
|
-- run fn = do
|
||||||
run "aoc2023/day2/eg.txt"
|
-- text <- readFile fn
|
||||||
run "aoc2023/day2/input.txt"
|
-- case mapM parseGame (split (trim text) "\n") of
|
||||||
|
-- Left err => putStrLn $ "fail " ++ err
|
||||||
|
-- Right games => do
|
||||||
|
-- putStrLn "part1"
|
||||||
|
-- printLn (part1 games)
|
||||||
|
-- putStrLn "part2"
|
||||||
|
-- printLn (part2 games)
|
||||||
|
|
||||||
|
-- main : IO Unit
|
||||||
|
-- main = do
|
||||||
|
-- run "aoc2023/day2/eg.txt"
|
||||||
|
-- run "aoc2023/day2/input.txt"
|
||||||
|
|||||||
@@ -1,42 +1,6 @@
|
|||||||
module Main
|
module Hello
|
||||||
|
|
||||||
-- Monad
|
import Prelude
|
||||||
|
|
||||||
class Monad (m : U → U) where
|
|
||||||
bind : {a b} → m a → (a → m b) → m b
|
|
||||||
pure : {a} → a → m a
|
|
||||||
|
|
||||||
infixl 1 _>>=_ _>>_
|
|
||||||
_>>=_ : {m} {{Monad m}} {a b} -> (m a) -> (a -> m b) -> m b
|
|
||||||
ma >>= amb = bind ma amb
|
|
||||||
|
|
||||||
_>>_ : {m} {{Monad m}} {a b} -> m a -> m b -> m b
|
|
||||||
ma >> mb = mb
|
|
||||||
|
|
||||||
-- I don't want to use an empty type because it would be a proof of void
|
|
||||||
ptype World
|
|
||||||
|
|
||||||
data IORes : U -> U where
|
|
||||||
MkIORes : {a : U} -> a -> World -> IORes a
|
|
||||||
|
|
||||||
IO : U -> U
|
|
||||||
IO a = World -> IORes a
|
|
||||||
|
|
||||||
|
|
||||||
data Unit : U where
|
|
||||||
MkUnit : Unit
|
|
||||||
|
|
||||||
|
|
||||||
instance Monad IO where
|
|
||||||
bind ma mab = \ w => case ma w of
|
|
||||||
MkIORes a w => mab a w
|
|
||||||
pure a = \ w => MkIORes a w
|
|
||||||
|
|
||||||
ptype String
|
|
||||||
pfunc putStrLn : String -> IO Unit := "(s) => (w) => {
|
|
||||||
console.log(s)
|
|
||||||
return MkIORes(Unit,MkUnit,w)
|
|
||||||
}"
|
|
||||||
|
|
||||||
main : IO Unit
|
main : IO Unit
|
||||||
main = do
|
main = do
|
||||||
|
|||||||
Reference in New Issue
Block a user