Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nicola Botta
IdrisLibs2
Commits
884df118
Commit
884df118
authored
Dec 21, 2020
by
Nicola Botta
Browse files
Initial.
parent
eda5a110
Changes
2
Hide whitespace changes
Inline
Side-by-side
LocalEffect/Exception.lidr
0 → 100644
View file @
884df118
> module LocalEffect.Exception
> import Effects
> import Effect.Exception
> import Nat.LTProperties
> import BoundedNat.BoundedNat
> import Sigma.Sigma
> import Pairs.Operations
> %default total
> %access public export
> ||| Parses a string for a Nat
> parseNat : String -> { [EXCEPTION String] } Eff Nat
> parseNat str
> = if all (\x => isDigit x) (unpack str)
> then pure (cast {to = Nat} (cast {to = Int} str))
> else raise "Not a Nat!"
> ||| Parses a string for a bounded Nat
> parseLTB : (b : Nat) -> String -> { [EXCEPTION String] } Eff (LTB b)
> {-
> parseLTB b str
> = if all (\x => isDigit x) (unpack str)
> then let n = cast {to = Nat} (cast {to = Int} str) in
> case (decLT n b) of
> (Yes p) => pure (MkSigma n p)
> (No _) => raise "Out of bound!"
> else raise "Not a Nat!"
> -}
> parseLTB b str
> = if all (\x => isDigit x) (unpack str)
> then let m = cast {to = Nat} (cast {to = Int} str) in
> case (decLT m b) of
> (Yes p) => pure (MkSigma m p)
> (No _) => raise "Out of bound!"
> else raise "Not a Nat!"
> ||| Parses a string for an Int
> parseInt : String -> { [EXCEPTION String] } Eff Int
> parseInt str
> = if all (\x => isDigit x || x == '-') (unpack str)
> then pure (cast {to = Int} str)
> else raise "Not an Int!"
LocalEffect/StdIO.lidr
0 → 100644
View file @
884df118
> module LocalEffect.StdIO
> import Effects
> import Effect.StdIO
> import Effect.Exception
> import LocalEffect.Exception
> import BoundedNat.BoundedNat
> import Sigma.Sigma
> import Pairs.Operations
> -- %default total
> %access public export
> |||
> -- %assert_total -- termination not required
> -- getNat : { [STDIO] } Eff Nat
> getNat : Eff Nat [STDIO]
> getNat =
> do putStr (" Nat: " )
> case the (Either String Nat) (run (parseNat (trim !getStr))) of
> Left err => do putStr (err ++ "\n")
> getNat
> Right n => do putStr "thanks!\n"
> pure n
> |||
> -- %assert_total -- termination not required
> getLTB : (b : Nat) -> { [STDIO] } Eff (LTB b)
> getLTB b =
> do putStr (" Nat, < " ++ cast {from = Int} (cast b) ++ ": " )
> case the (Either String (LTB b)) (run (parseLTB b (trim !getStr))) of
> Left err => do putStr (err ++ "\n")
> getLTB b
> Right n => do putStr "thanks!\n"
> pure n
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment