Split info into types/classes

This commit is contained in:
Chris Done 2019-11-25 14:23:33 +00:00
parent acb165ae1f
commit 19e0e51d9d
2 changed files with 19 additions and 13 deletions

View File

@ -71,25 +71,28 @@ syntax supported in Duet.
## Print built-in types and classes
To print all types (primitive or otherwise), classes and the instances
of each class, run:
To print all types (primitive or otherwise), run:
$ duet scope
$ duet types
Example output:
```haskell
Built-in types:
data Bool
= True
| False
data String
data Integer
data Rational
```
Built-in classes:
For classes and the instances of each class:
$ duet classes
Example output:
```haskell
class Num a where
plus :: forall a. (a -> a -> a)
times :: forall a. (a -> a -> a)

View File

@ -45,7 +45,8 @@ main = do
"Duet interpreter"
"This is the interpreter for the Duet mini-Haskell educational language"
(pure ())
(do addCommand "scope" "Print info about types and classes in scope" runDocPrint (pure ())
(do addCommand "types" "Print types in scope" runTypesPrint (pure ())
addCommand "classes" "Print types in scope" runClassesPrint (pure ())
addCommand
"run"
"Run the given program source"
@ -69,10 +70,9 @@ main = do
(long "hide-steps" <> help "Do not print the steps to stdout")))
cmd
runDocPrint :: () -> IO ()
runDocPrint _ = do
runTypesPrint :: () -> IO ()
runTypesPrint _ = do
builtins <- evalSupplyT (setupEnv mempty []) [1 ..]
putStrLn "Built-in types:\n"
putStrLn
(printDataType
defaultPrint
@ -96,12 +96,15 @@ runDocPrint _ = do
(printTypeConstructorOpaque
defaultPrint
(specialTypesRational (builtinsSpecialTypes builtins)))
putStrLn "\nBuilt-in classes:\n"
where
printTypeConstructorOpaque p = ("data " ++) . printTypeConstructor p
runClassesPrint :: () -> IO ()
runClassesPrint _ = do
builtins <- evalSupplyT (setupEnv mempty []) [1 ..]
mapM_
(putStrLn . (++ "\n") . printClass defaultPrint (builtinsSpecialTypes builtins))
(M.elems (builtinsTypeClasses builtins))
where
printTypeConstructorOpaque p = ("data " ++) . printTypeConstructor p
runProgram :: Run -> IO ()
runProgram run@Run {..} = do