Skip to content

Commit

Permalink
v0.44.0 - ad hoc polymorphisms (almost typeclasses)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendsee committed Feb 9, 2024
2 parents 95f1012 + c26f1f1 commit dd18a73
Show file tree
Hide file tree
Showing 85 changed files with 2,974 additions and 2,292 deletions.
16 changes: 15 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ handling for several very different languages (proofs-of-concept).
-------------------
- [ ] add Haskell support

- [ ] typeclasses
- [ ] algebraic types
- [ ] pattern matching
- [ ] constraint checking
Expand Down Expand Up @@ -57,6 +56,21 @@ handling for several very different languages (proofs-of-concept).
- [ ] Update Hackage release
- [ ] Ensure github actions passes


0.44.0 [2024.02.08]
-------------------

Add support for ad hoc polymorphism.
* Support sources and declarations in classes
* Support multiple parameters
* Support overlapping instances
* Packers are now implemented through the `Packable` typeclass

Some missing features:
* No support typeclass constraints in the type signatures.
* No support for parameterized class variables
* No support for polymorphic recursion (does anyone want that?)

0.43.0 [2024.01.14]
-------------------

Expand Down
2 changes: 1 addition & 1 deletion executable/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main where

import Subcommands (runMorloc)
import UI
import UI
import Options.Applicative

main :: IO ()
Expand Down
17 changes: 8 additions & 9 deletions executable/Subcommands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-|
Module : Subcommands
Description : Morloc executable subcommands
Copyright : (c) Zebulun Arendsee, 2021
Copyright : (c) Zebulun Arendsee, 2016-2024
License : GPL-3
Maintainer : zbwrnz@gmail.com
Stability : experimental
Expand All @@ -21,8 +21,6 @@ import qualified Morloc.Frontend.API as F
import qualified Morloc.Data.GMap as GMap
import Morloc.CodeGenerator.Namespace (SerialManifold(..))
import Morloc.CodeGenerator.Grammars.Translator.PseudoCode (pseudocodeSerialManifold)
import Morloc.Pretty ()
import Morloc.Frontend.Pretty ()
import Morloc.Data.Doc
import Text.Megaparsec.Error (errorBundlePretty)
import qualified Data.Map as Map
Expand Down Expand Up @@ -107,28 +105,29 @@ cmdTypecheck args _ config = do
config
(M.typecheckFrontend path code) |>> writeFrontendTypecheckOutput verbosity >>= (\s -> putDoc (s <> "\n"))

writeFrontendTypecheckOutput :: Int -> ((Either MorlocError [SAnno (Indexed TypeU) Many Int], [MT.Text]), MorlocState) -> MDoc
writeFrontendTypecheckOutput :: Int -> ((Either MorlocError [AnnoS (Indexed TypeU) Many Int], [MT.Text]), MorlocState) -> MDoc
writeFrontendTypecheckOutput _ ((Left e, _), _) = pretty e
writeFrontendTypecheckOutput 0 ((Right xs, _), s) = vsep (map (writeFrontendTypes s) xs)
writeFrontendTypecheckOutput 1 ((Right xs, _), s) = "\nExports:\n\n" <> vsep (map (writeFrontendTypes s) xs)
writeFrontendTypecheckOutput _ _ = "I don't know how to be that verbose"

writeFrontendTypes :: MorlocState -> SAnno (Indexed TypeU) Many Int -> MDoc
writeFrontendTypes s (SAnno _ (Idx gidx t)) = writeTerm s gidx (pretty t)
writeFrontendTypes :: MorlocState -> AnnoS (Indexed TypeU) Many Int -> MDoc
writeFrontendTypes s (AnnoS (Idx gidx t) _ _) = writeTerm s gidx (pretty t)

writeTerm :: MorlocState -> Int -> MDoc -> MDoc
writeTerm s i typeDoc =
case ( Map.lookup i (stateName s)
, GMap.lookup i (stateSignatures s))
of
(Just v, GMapJust TermTypes{termGeneral = Just t'}) -> pretty v <+> "::" <+> pretty t'
(Just v, GMapJust (Monomorphic TermTypes{termGeneral = Just t'})) -> pretty v <+> "::" <+> pretty t'
(Just _, GMapJust (Polymorphic cls v t _)) -> "class" <+> pretty cls <+> pretty v <+> "::" <+> pretty (etype t)
(Just v, _) -> pretty v <+> "|-" <+> typeDoc
_ -> "MISSING"


writeTypecheckOutput :: Int -> ((Either MorlocError [(Lang, [SerialManifold])], [MT.Text]), MorlocState) -> MDoc
writeTypecheckOutput _ ((Left e, _), _) = pretty e
writeTypecheckOutput _ ((Right pools, _), _) = vsep $ map (uncurry writePool) pools
writeTypecheckOutput _ ((Right pools, _), _) = vsep $ map (uncurry writePool) pools

writePool :: Lang -> [SerialManifold] -> MDoc
writePool lang manifolds = pretty lang <+> "pool:" <> "\n" <> vsep (map pseudocodeSerialManifold manifolds) <> "\n"
Expand All @@ -146,4 +145,4 @@ cmdDump args _ config = do
prettyDAG :: DAG MVar e ExprI -> MDoc
prettyDAG m0 = vsep (map prettyEntry (Map.toList m0)) where
prettyEntry :: (MVar, (ExprI, [(MVar, e)])) -> MDoc
prettyEntry (k, (n, _)) = block 4 (pretty k) (vsep [pretty n])
prettyEntry (k, (n, _)) = block 4 (pretty k) (vsep [pretty n])
10 changes: 5 additions & 5 deletions executable/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ opts :: ParserInfo CliCommand
opts = info (cliParser <**> helper)
( fullDesc
<> progDesc "call 'morloc make -h', 'morloc install -h', etc for details"
<> header "morloc v0.43.0" -- FIXME: HARDCODED VERSION NUMBER!!!
<> header "morloc v0.44.0" -- FIXME: HARDCODED VERSION NUMBER!!!
)


Expand Down Expand Up @@ -43,7 +43,7 @@ data MakeCommand = MakeCommand

makeCommandParser :: Parser MakeCommand
makeCommandParser = MakeCommand
<$> optExpression
<$> optExpression
<*> optConfig
<*> optVerbose
<*> optVanilla
Expand All @@ -70,7 +70,7 @@ makeInstallParser = InstallCommand
<*> optVanilla
<*> optModuleName

installSubcommand :: Mod CommandFields CliCommand
installSubcommand :: Mod CommandFields CliCommand
installSubcommand = command "install" (info (CmdInstall <$> makeInstallParser) (progDesc "install a morloc module"))


Expand All @@ -96,12 +96,12 @@ makeTypecheckParser = TypecheckCommand
<*> optRealize
<*> optScript

typecheckSubcommand :: Mod CommandFields CliCommand
typecheckSubcommand :: Mod CommandFields CliCommand
typecheckSubcommand =
command "typecheck" (info (CmdTypecheck <$> makeTypecheckParser) (progDesc "typecheck a morloc program"))


dumpSubcommand :: Mod CommandFields CliCommand
dumpSubcommand :: Mod CommandFields CliCommand
dumpSubcommand =
command "dump" (info (CmdDump <$> makeDumpParser) (progDesc "dump parsed code"))

Expand Down
2 changes: 1 addition & 1 deletion library/Morloc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Morloc.Frontend.Treeify (treeify)
typecheckFrontend
:: Maybe Path
-> Code
-> MorlocMonad [SAnno (Indexed TypeU) Many Int]
-> MorlocMonad [AnnoS (Indexed TypeU) Many Int]
typecheckFrontend path code
-- Maybe Path -> Text -> [Module]
-- parse code into unannotated modules
Expand Down
2 changes: 1 addition & 1 deletion library/Morloc/BaseTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-|
Module : Morloc.BaseTypes
Description : Definitions and functions for handling base types
Copyright : (c) Zebulun Arendsee, 2023
Copyright : (c) Zebulun Arendsee, 2016-2024
License : GPL-3
Maintainer : zbwrnz@gmail.com
Stability : experimental
Expand Down
Loading

0 comments on commit dd18a73

Please sign in to comment.