mirror of
https://github.com/Noratrieb/idris-learning.git
synced 2026-01-14 13:05:02 +01:00
size command
This commit is contained in:
parent
941f8e2020
commit
eda0cba251
1 changed files with 6 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ addToStore (MkData size items) newitem = MkData _ (addToData items)
|
|||
|
||||
data Command = Add String
|
||||
| Get Integer
|
||||
| Size
|
||||
| Quit
|
||||
|
||||
parseCommand : (cmd : String) -> (args : String) -> Maybe Command
|
||||
|
|
@ -29,6 +30,7 @@ parseCommand "get" val = case all isDigit (unpack val) of
|
|||
True => Just (Get (cast val))
|
||||
False => Nothing
|
||||
parseCommand "quit" args = Just Quit
|
||||
parseCommand "size" args = Just Size
|
||||
parseCommand _ _ = Nothing
|
||||
|
||||
parse : (input : String) -> Maybe Command
|
||||
|
|
@ -46,10 +48,11 @@ getEntry pos store = let store_items = items store in
|
|||
processInput : DataStore -> String -> Maybe (String, DataStore)
|
||||
processInput store inp = case parse inp of
|
||||
Nothing => Just ("invalid command\n", store)
|
||||
(Just (Add item)) =>
|
||||
Just (Add item) =>
|
||||
Just ("ID " ++ show (size store) ++ "\n", addToStore store item)
|
||||
(Just (Get pos)) => getEntry pos store
|
||||
(Just Quit) => Nothing
|
||||
Just (Get pos) => getEntry pos store
|
||||
Just Size => Just ("Size: " ++ show (size store) ++ "\n", store)
|
||||
Just Quit => Nothing
|
||||
|
||||
|
||||
main : IO ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue