shithub: MicroHs

Download patch

ref: 82b07338710f9c928e7cddfd2554ee62a4eb2e39
parent: 11a32d05eefc1d6cabd5312af46eba9b793174fd
author: Lennart Augustsson <lennart@augustsson.net>
date: Tue Dec 26 04:41:14 EST 2023

Complain about extra bindings in instances

--- a/README.md
+++ b/README.md
@@ -2,6 +2,8 @@
 This directory contains an implementation of a small subset of Haskell.
 It uses combinators for the runtime execution.
 
+The runtime system has minimal dependencies, and can be compiled even for micro-controllers.
+
 The compiler can compile itself.
 
 ## Compiling MicroHs
@@ -28,12 +30,11 @@
 Differences:
  * Top level definitions must have a type signature.
  * Type variables need an explicit `forall`.
- * Type variables without a kind annotation are assumed to have kind `Type`.
  * There is no `Read` class.
  * There is no deriving.
- * There is no record syntax.
+ * Indentation is handled a little differently.
  * The `Prelude` has to be imported explicitly.
- * Polymorphic types are never inferred; use a type signature if you need it.
+ * Polymorphic types/kinds are never inferred; use a type/kind signature if you need it.
  * A module must have an export list.
  * The `default` list is empty, except in the interactive system.
  * Always enabled extension:
--- a/src/MicroHs/TCMonad.hs
+++ b/src/MicroHs/TCMonad.hs
@@ -150,11 +150,11 @@
   uvarSubst   :: (IM.IntMap EType),     -- mapping from unique id to type
   tcMode      :: TCMode,                -- pattern, value, or type
   classTable  :: ClassTable,            -- class info, indexed by QIdent
-  ctxTables   :: (InstTable,           -- instances
-                  MetaTable,           -- instances with unification variables
+  ctxTables   :: (InstTable,            -- instances
+                  MetaTable,            -- instances with unification variables
                   TypeEqTable),         -- type equalities
   constraints :: Constraints,           -- constraints that have to be solved
-  defaults    :: Defaults              -- current defaults
+  defaults    :: Defaults               -- current defaults
   }
 
 typeTable :: TCState -> TypeTable
--- a/src/MicroHs/TypeCheck.hs
+++ b/src/MicroHs/TypeCheck.hs
@@ -1186,6 +1186,9 @@
       meths = map meth mis
       sups = map (const (EVar $ mkIdentSLoc loc dictPrefixDollar)) supers
       args = sups ++ meths
+  case map fst ies \\ mis of
+    [] -> return ()
+    i:_ -> tcError (getSLoc i) $ "superflous binding " ++ show i
   let bind = Fcn iInst $ eEqns [] $ foldl EApp (EVar $ mkClassConstructor qiCls) args
   mn <- gets moduleName
   addInstTable [(EVar $ qualIdent mn iInst, vks, ctx, cc, fds)]
--- a/tests/errmsg.test
+++ b/tests/errmsg.test
@@ -157,4 +157,12 @@
 mhs: "../tmp/E.hs": line 6, col 11: existentials not allowed in pattern binding
 
 =====
+module E() where
+import Prelude
+class C a where { m :: a }
+instance C Int where { x = 1 }
+-----
+mhs: "../tmp/E.hs": line 5, col 24: superflous binding x
+
+=====
 END
--