This commit is contained in:
Chris Done 2019-11-15 16:32:21 +01:00
parent 9b776ff39b
commit 6f23223717
3 changed files with 33 additions and 11 deletions

View File

@ -20,3 +20,24 @@ Available options:
Available commands:
run Run the given program source
```
Example:
integers.hs:
```haskell
main = 3 + ((2 + -3) - 3)
```
Output for this program:
``` haskell
$ duet run examples/integers.hs
[1]
3 + ((2 + -3) - 3)
[2]
3 + (-1 - 3)
[3]
3 + -4
[4]
-1
```

View File

@ -39,7 +39,7 @@ main = do
(Run <$>
strArgument (metavar "FILEPATH" <> help "The .hs file to interpret") <*>
strOption
(long "--main" <> metavar "NAME" <> help "The main value to run" <>
(long "main" <> metavar "NAME" <> help "The main value to run" <>
value "main") <*>
option
auto

View File

@ -1,13 +1,14 @@
go = \n res ->
case n of
0 -> 1
n -> go (n - 1) (res * n)
factorial = \n -> case n of
0 -> 1
1 -> 1
_ -> n * factorial (n - 1)
fac = \n -> go n 1
factorial = \n ->
case n of
0 -> 1
n -> n * factorial (n - 1)
go =
\n acc ->
case n of
0 -> 1
1 -> 1
_ -> go (n - 1) (n * acc)
main = fac 5
it = go 5 1