Search in sources :

Example 1 with ParametricFunctionDecl

use of abs.frontend.ast.ParametricFunctionDecl in project abstools by abstools.

the class TypingTest method functionTypeArgs4.

@Test
public void functionTypeArgs4() {
    Model m = assertParseOkStdLib(" data Foo<A> = Bar(A,Bool); " + "def Bool f<A>(Foo<A> o) = case o { Bar(a,b) => b; } ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    Type type = ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(m.getBoolType(), type);
}
Also used : ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) Type(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) UnionType(abs.frontend.typechecker.UnionType) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 2 with ParametricFunctionDecl

use of abs.frontend.ast.ParametricFunctionDecl in project abstools by abstools.

the class TypingTest method functionTypeArgs2.

@Test
public void functionTypeArgs2() {
    Model m = assertParseOkStdLib(" def Maybe<A> f<A>(Maybe<A> o) = o ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    assertEquals(d.getTypeUse().getType(), ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType());
}
Also used : ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 3 with ParametricFunctionDecl

use of abs.frontend.ast.ParametricFunctionDecl in project abstools by abstools.

the class TypingTest method functionTypeArgs5.

@Test
public void functionTypeArgs5() {
    Model m = assertParseOkStdLib("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(typeParameter.getName(), type.getDecl().getName());
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 4 with ParametricFunctionDecl

use of abs.frontend.ast.ParametricFunctionDecl in project abstools by abstools.

the class TypingTest method functionTypeArgs.

@Test
public void functionTypeArgs() {
    Model m = assertParseOkStdLib(" def Maybe<A> f<A>() = None ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    DataTypeType t = (DataTypeType) d.getTypeUse().getType();
    TypeParameter typeArg = (TypeParameter) t.getTypeArg(0);
    assertEquals(typeArg.getDecl(), d.getTypeParameter(0));
}
Also used : ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with ParametricFunctionDecl

use of abs.frontend.ast.ParametricFunctionDecl in project abstools by abstools.

the class TypingTest method functionTypeArgs3.

@Test
public void functionTypeArgs3() {
    Model m = assertParseOkStdLib(" def A f<A>(Maybe<A> o) = case o { Just(a) => a; } ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    TypeParameterDecl decl = type.getDecl();
    assertEquals(typeParameter, decl);
}
Also used : TypeParameterDecl(abs.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(abs.frontend.ast.ParametricFunctionDecl) TypeParameter(abs.frontend.typechecker.TypeParameter) Model(abs.frontend.ast.Model) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

FrontendTest (abs.frontend.FrontendTest)6 Model (abs.frontend.ast.Model)6 ParametricFunctionDecl (abs.frontend.ast.ParametricFunctionDecl)6 Test (org.junit.Test)6 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)3 TypeParameter (abs.frontend.typechecker.TypeParameter)3 TypeParameterDecl (abs.frontend.ast.TypeParameterDecl)2 DataTypeType (abs.frontend.typechecker.DataTypeType)2 Type (abs.frontend.typechecker.Type)1 UnionType (abs.frontend.typechecker.UnionType)1