Skip to content

Commit

Permalink
frege-repl-13 Support inline definition with type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmhelloworld committed Nov 13, 2014
1 parent a141562 commit 04a9019
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ scriptTypePass src = do
[] -> return SourceType.ModuleSource
(Token{tokid=PACKAGE}) : _ -> return SourceType.ModuleSource
_ -> do
isExpr <- expressionPass src
if isExpr
then return SourceType.ExpressionSource
else return SourceType.DefinitionsSource
isDef <- isDefinition src
if isDef
then return SourceType.DefinitionsSource
else return SourceType.ExpressionSource

noDocComment Token{tokid} = tokid != COMMENT && tokid != DOCUMENTATION

Expand Down Expand Up @@ -571,13 +571,12 @@ iparsePass f = do
indent n src = (unlines . map (spaces ++) . lines $ src) where
spaces = concat $ replicate n " "

expressionPass :: String -> StG Bool
expressionPass src = do
isDefinition :: String -> StG Bool
isDefinition src = do
g <- getST
sw <- doio $ StringWriter.new ()
pw <- doio $ sw.printer
let varDecl = variableDeclScript "f" src
modDecl = intercalate newLine ["module T where", varDecl]
let modDecl = intercalate newLine ["module T where", src]
changeST Global.{sub <- SubSt.{stderr=pw}}
runpass (lexPass modDecl, "lexical analysis ", postTrue)
g <- getST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public void testDefinition() throws ScriptException {
assertEquals(expected, actual);
}

@Test
public void testInlineDefinitionWithTypeAnn() throws ScriptException {
frege.eval("type F = (forall b. [b] -> [b]) -> Int");
frege.eval("g :: F -> Int; g f = f reverse");
frege.eval("k2 (f :: [Int] -> [Int]) = 42");
final Object expected = frege.eval("g k2");
final Object actual = 42;
assertEquals(expected, actual);
}

@Test
public void testBinding() throws ScriptException {
frege.put("bar", new BigInteger("12312332142343244"));
Expand Down

0 comments on commit 04a9019

Please sign in to comment.