forked from area9innovation/flow9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfctype.flow
More file actions
57 lines (40 loc) · 1.8 KB
/
Copy pathfctype.flow
File metadata and controls
57 lines (40 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import maybe;
export {
// Types as they are expressed in flow programs, that programmers understand
FcType ::= FcBaseType, FcTypeArray, FcTypeFunction, FcTypeRef, FcTypeParameter,
FcTypeFlow, FcTypeName,
FcTypeStruct, FcTypeUnion,
FcTypeVar;
FcBaseType ::= FcTypeVoid, FcTypeBool, FcTypeInt, FcTypeDouble, FcTypeString, FcTypeNative;
FcTypeArray(t : FcType, info : FcInfo2);
FcTypeFunction(args : [FcFunArg], returnType : FcType, info : FcInfo2);
FcFunArg(name : string, type : FcType);
FcTypeFunction2(args : [FcFunArg2], returnType : Maybe<FcType>, info : FcInfo2); // The return type is optional
FcFunArg2(name : string, type : Maybe<FcType>); // The type is optional
FcTypeRef(t : FcType, info : FcInfo2);
FcTypeParameter(n : string, info : FcInfo2); // ?, ?? and so on
FcTypeBool(info : FcInfo2);
FcTypeInt(info : FcInfo2);
FcTypeDouble(info : FcInfo2);
FcTypeString(info : FcInfo2);
FcTypeFlow(info : FcInfo2);
FcTypeVoid(info : FcInfo2);
FcTypeNative(info : FcInfo2);
// Struct or union. If the name is empty, all we know is that it is a struct
FcTypeName(name : string, typeparameters : [FcType], info : FcInfo2);
// typars is when a type is instantiated
FcTypeStruct(name : string, typars : [FcType], args : [FcStructArg], info : FcInfo2);
FcStructArg(name : string, type : FcType, ismutable : bool);
FcTypeUnion(name : string, typeparameters : [FcType], typenames : [FcTypeName], info : FcInfo2);
// While type-checking, we introduce type variables for unknown types
FcTypeVar(id : int, info : FcInfo2);
FcArgType ::= FcStructArg, FcFunArg;
FcInfo2(start : int, end : int);
dummyType = FcTypeVoid(FcInfo2(0, 0));
}
/*
foo(f : (int) -> double) -> void
foo : (f: - type(f)) -> void
= (f: - ((-int) -> double)) -> void
= (f: (int) -> -double) -> void
*/