ggreif / omega

Automatically exported from code.google.com/p/omega
Other
7 stars 0 forks source link

multiple type declarations on one line not allowed #19

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Create this file:

ggreif@my [!125] cat tes.hs 
a, b :: Int
a = 4
b = 3

ghci loads it without error,
Omega complains:

ggreif@my [!126] omega tes.hs 
Omega Interpreter: version 1.4.2
Build Date: Tue Jun 12 16:20:11 Pacific Daylight Time 2007

Type ':?' for command line help.
Loading source files = ["tes.hs"]
"tes.hs" (line 1, column 1) tabs [1]:
unexpected "a, b :: Int
a = 4
b ..."
            ^
expecting: layout opening brace, or decl

Original issue reported on code.google.com by ggr...@gmail.com on 11 Jul 2007 at 4:45

GoogleCodeExporter commented 9 years ago
this is not so easy:
 * constructors can be given a type signature too
 * type signatures can be specified for local functions (where f :: A -> B)
 * type functions always have a type signature

that said, I am attaching a patch (for archival) but it is not functional yet.
The main problem is that the parser cannot transparently produce
many (Parser Dec) objects, but only some grouped Dec (as in the patch) or a 
(Parser
[Dec]), which does not match with the rest and has similar problems.

Original comment by ggr...@gmail.com on 11 Dec 2007 at 2:40

Attachments:

GoogleCodeExporter commented 9 years ago
I think there is a real bug, though:

Index: Syntax.hs
===================================================================
--- Syntax.hs   (revision 49)
+++ Syntax.hs   (working copy)
@@ -244,7 +245,8 @@
 isTypeSyn _ = False

 isTypeFun (TypeFun _ _ _ _) = True
-isTypeFun (TypeSig loc (Global (x:xs)) pt) = True
+isTypeFun (TypeSig loc (Global (x:xs)) (Karrow' _ _)) | isLower x = True
+--isTypeFun (TypeSig loc (Global (x:xs)) pt) = True
 isTypeFun _ = False

 isTheorem (AddTheorem _ _ ) = True

isTypeFun should check for the Karrow, the isLower test is just paranoia.

Original comment by ggr...@gmail.com on 11 Dec 2007 at 2:42

GoogleCodeExporter commented 9 years ago
It is already possible to interleave type declarations and definitions, see:

http://code.google.com/p/omega/source/browse/trunk/tests/Unification.prg?spec=sv
n687&r=687#12

So there already must be a mechanism to store signatures which are added to a 
scope.

That said, we could simply make a
data Dec = ...
    | MultiTypeSig Loc [Var] PT

And later drop the "Multi"...

Original comment by ggr...@gmail.com on 1 Feb 2011 at 11:36

GoogleCodeExporter commented 9 years ago
r694-r697 fixes this. I succeeded along the lines of comment 3 :-)

TypeSigs with multiple variables are expanded out before digesting, so later we 
only have to deal with singleton variable lists in TypeSigs.

Original comment by ggr...@gmail.com on 2 Feb 2011 at 3:20