2module Types.Hints (hints) where
4import Control.Monad (liftM,mapM)
5import Control.Arrow (first)
7import Types.Substitutions (rescheme)
10-------- Text and Elements --------
12str2elem = hasType (string ==> element) [ "plainText" ]
14textToText = [ "header", "italic", "bold", "underline"
15 , "overline", "strikeThrough", "monospace" ]
17textAttrs = [ "toText" -: string ==> text
18 , "typeface" -: string ==> text ==> text
19 , "link" -:: string ==> a ==> a
20 , numScheme (\t -> t ==> text ==> text) "Text.height"
21 ] ++ hasType (text ==> text) textToText
23elements = let iee = int ==> element ==> element in
24 [ "flow" -: direction ==> listOf element ==> element
25 , "layers" -: listOf element ==> element
26 , "text" -: text ==> element
27 , "image" -: int ==> int ==> string ==> element
28 , "video" -: int ==> int ==> string ==> element
29 , "opacity" -: float ==> element ==> element
32 , "size" -: int ==> iee
33 , "widthOf" -: element ==> int
34 , "heightOf"-: element ==> int
35 , "sizeOf" -: element ==> pairOf int
36 , "color" -: color ==> element ==> element
37 , "container" -: int ==> int ==> position ==> element ==> element
38 , "spacer" -: int ==> int ==> element
39 , "rightedText" -: text ==> element
40 , "centeredText" -: text ==> element
41 , "justifiedText" -: text ==> element
42 , "asText" -:: a ==> element
43 , "show" -:: a ==> text
44 , "collage" -: int ==> int ==> listOf form ==> element
45 , "fittedImage" -: int ==> int ==> string ==> element
48directions = hasType direction ["up","down","left","right","inward","outward"]
50 hasType position ["topLeft","midLeft","bottomLeft","midTop","middle"
51 ,"midBottom","topRight","midRight","bottomRight"] ++
52 hasType (location ==> position)
53 ["topLeftAt","bottomLeftAt","middleAt","topRightAt","bottomRightAt"] ++
54 [ "absolute" -: int ==> location, "relative" -: float ==> location ]
55colors = [ numScheme (\n -> n ==> n ==> n ==> color) "rgb"
56 , numScheme (\n -> n ==> n ==> n ==> n ==> color) "rgba"
57 ] ++ hasType color ["red","green","blue","black","white"
58 ,"yellow","cyan","magenta","grey","gray"]
60lineTypes = [ numScheme (\n -> listOf (pairOf n) ==> line) "line"
61 , numScheme (\n -> pairOf n ==> pairOf n ==> line) "segment"
62 , "customLine" -: listOf int ==> color ==> line ==> form
63 ] ++ hasType (color ==> line ==> form) ["solid","dashed","dotted"]
65shapes = [ twoNums (\n m -> listOf (pairOf n) ==> pairOf m ==> shape) "polygon"
66 , "filled" -: color ==> shape ==> form
67 , "outlined" -: color ==> shape ==> form
68 , "textured" -: string ==> shape ==> form
69 , "customOutline" -: listOf int ==> color ==> shape ==> form
70 ] ++ map (twoNums (\n m -> n ==> n ==> pairOf m ==> shape)) [ "ngon"
74collages = [ numScheme (\n -> pairOf n ==> element ==> form) "toForm"
75 , numScheme (\n -> string ==> n ==> n ==> pairOf n ==> form) "sprite"
76 , numScheme (\n -> n ==> n ==> form ==> form) "move"
77 , numScheme (\n -> n ==> form ==> form) "rotate"
78 , numScheme (\n -> n ==> form ==> form) "scale"
81-------- Foreign --------
84 [ "castJSBoolToBool" -: jsBool ==> bool
85 , "castBoolToJSBool" -: bool ==> jsBool
86 , "castJSNumberToInt" -: jsNumber ==> int
87 , "castIntToJSNumber" -: int ==> jsNumber
88 , "castJSElementToElement" -: int ==> int ==> jsElement ==> element
89 , "castElementToJSElement" -: element ==> jsElement
90 , "castJSStringToString" -: jsString ==> string
91 , "castStringToJSString" -: string ==> jsString
92 , "castJSNumberToFloat" -: jsNumber ==> float
93 , "castFloatToJSNumber" -: float ==> jsNumber
96castToTuple n = (,) name $ Forall [1..n] [] (jsTuple vs ==> tupleOf vs)
97 where vs = map VarT [1..n]
98 name = "castJSTupleToTuple" ++ show n
99castToJSTuple n = (,) name $ Forall [1..n] [] (tupleOf vs ==> jsTuple vs)
100 where vs = map VarT [1..n]
101 name = "castTupleToJSTuple" ++ show n
104 map castToTuple [2..5] ++ map castToJSTuple [2..5] ++
105 [ "castJSArrayToList" -:: jsArray a ==> listOf a
106 , "castListToJSArray" -:: listOf a ==> jsArray a
110 [ "JsonString" -: string ==> jsonValue
111 , "JsonBool" -: bool ==> jsonValue
112 , "JsonNull" -: jsonValue
113 , "JsonArray" -: listOf jsonValue ==> jsonValue
114 , "JsonObject" -: jsonObject ==> jsonValue
115 , numScheme (\n -> n ==> jsonValue) "JsonNumber"
116 , "toPrettyString" -: string ==> jsonObject ==> string
117 , "toPrettyJSString" -: string ==> jsonObject ==> jsString
118 , "toJSString" -: jsonObject ==> jsString
122-------- Signals --------
124sig n name = (,) name $ Forall [1..n] [] (fn ts ==> fn (map signalOf ts))
125 where fn = foldr1 (==>)
134 , "foldp" -:: (a ==> b ==> b) ==> b ==> signalOf a ==> signalOf b
135 , "foldp1" -:: (a ==> b ==> b) ==> (a ==> b) ==> signalOf a ==> signalOf b
136 , "randomize" -:: int ==> int ==> signalOf a ==> signalOf int
137 , "count" -:: signalOf a ==> signalOf int
138 , "keepIf" -:: (a==>bool) ==> a ==> signalOf a ==> signalOf a
139 , "dropIf" -:: (a==>bool) ==> a ==> signalOf a ==> signalOf a
140 , "keepWhen" -:: signalOf bool ==>a==> signalOf a ==> signalOf a
141 , "dropWhen" -:: signalOf bool ==>a==> signalOf a ==> signalOf a
142 , "dropRepeats" -:: signalOf a ==> signalOf a
143 , "sampleOn" -:: signalOf a ==> signalOf b ==> signalOf b
147 [ "keysDown" -: signalOf (listOf int)
148 , "charPressed" -: signalOf (maybeOf int)
149 , "inRange" -: int ==> int ==> signalOf int
150 , timeScheme "every" (\t -> t ==> signalOf t)
151 , timeScheme "before" (\t -> t ==> signalOf bool)
152 , timeScheme "after" (\t -> t ==> signalOf bool)
153 , "dimensions" -: signalOf point
154 , "position" -: signalOf point
155 , "x" -: signalOf int
156 , "y" -: signalOf int
157 , "isDown" -: signalOf bool
158 , "isClicked" -: signalOf bool
159 , "textField" -: string ==> tupleOf [element, signalOf string]
160 , "password" -: string ==> tupleOf [element, signalOf string]
161 , "textArea" -: int ==> int ==> tupleOf [element, signalOf string]
162 , "checkBox" -: bool ==> tupleOf [element, signalOf bool]
163 , "button" -: string ==> tupleOf [element, signalOf bool]
164 , "stringDropDown" -: listOf string ==> tupleOf [element, signalOf string]
167-------- Math and Binops --------
169binop t = t ==> t ==> t
170scheme1 super t name =
171 (name, Forall [0] [ Context ("`" ++ name ++ "'") $ VarT 0 :<: super
173scheme2 s1 s2 t name =
174 (name, Forall [0,1] [ Context ("`" ++ name ++ "'") $ VarT 0 :<: s1
175 , Context ("`" ++ name ++ "'") $ VarT 1 :<: s2
176 ] (t (VarT 0) (VarT 1)))
177numScheme t name = scheme1 number t name
178timeScheme name t = scheme1 time t name
179twoNums f name = scheme2 number number f name
182 map (numScheme (\t -> t ==> binop t)) ["clamp"] ++
183 map (numScheme (\t -> binop t)) ["+","-","*","max","min"] ++
184 [ numScheme (\t -> t ==> t) "abs" ] ++
185 hasType (binop float) [ "/", "logBase" ] ++
186 hasType (binop int) ["rem","div","mod"] ++
187 hasType (float ==> float) ["sin","cos","tan","asin","acos","atan","sqrt"] ++
188 hasType float ["pi","e"] ++
189 hasType (int ==> float) ["toFloat","castIntToFloat"] ++
190 hasType (float ==> int) ["round","floor","ceiling","truncate"]
193 [ "not" -: bool ==> bool ] ++
194 hasType (binop bool) ["&&","||"] ++
195 map (scheme1 comparable (\t -> t ==> t ==> bool)) ["<",">","<=",">="] ++
197 , Forall [0,1] [ Context "`compare'" $ VarT 0 :<: comparable ] (VarT 0 ==> VarT 0 ==> VarT 1) )
200-------- Polymorphic Functions --------
202[a,b,c] = map VarT [1,2,3]
205name -:: tipe = (name, Forall [1,2,3] [] tipe)
209 , "==" -:: a ==> a ==> bool
210 , "/=" -:: a ==> a ==> bool
211 , "flip" -:: (a ==> b ==> c) ==> (b ==> a ==> c)
212 , "." -:: (b ==> c) ==> (a ==> b) ==> (a ==> c)
213 , "$" -:: (a ==> b) ==> a ==> b
214 , ":" -:: a ==> listOf a ==> listOf a
215 , (,) "++" . Forall [0,1] [ Context "`++'" $ VarT 0 :<: appendable (VarT 1) ] $ VarT 0 ==> VarT 0 ==> VarT 0
216 , "Cons" -:: a ==> listOf a ==> listOf a
218 , "Just" -:: a ==> maybeOf a
219 , "Nothing" -:: maybeOf a
220 , "curry" -:: (tupleOf [a,b] ==> c) ==> a ==> b ==> c
221 , "uncurry" -:: (a ==> b ==> c) ==> tupleOf [a,b] ==> c
222 ] ++ map tuple [0..8]
224tuple n = ("Tuple" ++ show n, Forall [1..n] [] $ foldr (==>) (tupleOf vs) vs)
225 where vs = map VarT [1..n]
228 [ "and" -:: listOf bool ==> bool
229 , "or" -:: listOf bool ==> bool
230 , numScheme (\n -> listOf n ==> listOf n) "sort"
231 , "head" -:: listOf a ==> a
232 , "tail" -:: listOf a ==> listOf a
233 , "length" -:: listOf a ==> int
234 , "filter" -:: (a ==> bool) ==> listOf a ==> listOf a
235 , "foldr1" -:: (a ==> a ==> a) ==> listOf a ==> a
236 , "foldl1" -:: (a ==> a ==> a) ==> listOf a ==> a
237 , "scanl1" -:: (a ==> a ==> a) ==> listOf a ==> a
238 , "forall" -:: (a ==> bool) ==> listOf a ==> bool
239 , "exists" -:: (a ==> bool) ==> listOf a ==> bool
240 , "reverse" -:: listOf a ==> listOf a
241 , "take" -:: int ==> listOf a ==> listOf a
242 , "drop" -:: int ==> listOf a ==> listOf a
243 , "partition" -:: (a ==> bool) ==> listOf a ==> tupleOf [listOf a,listOf a]
244 , "intersperse" -:: a ==> listOf a ==> listOf a
245 , "zip" -:: listOf a ==>listOf b ==>listOf(tupleOf [a,b])
246 , "map" -:: (a ==> b) ==> listOf a ==> listOf b
247 , "foldr" -:: (a ==> b ==> b) ==> b ==> listOf a ==> b
248 , "foldl" -:: (a ==> b ==> b) ==> b ==> listOf a ==> b
249 , "scanl" -:: (a ==> b ==> b) ==> b ==> listOf a ==> listOf b
250 , (,) "concat" . Forall [0,1] [ Context "`concat'" $ VarT 0 :<: appendable (VarT 1) ] $
251 listOf (VarT 0) ==> VarT 0
252 , (,) "concatMap" . Forall [0,1,2] [ Context "`concatMap'" $ VarT 0 :<: appendable (VarT 1) ] $
253 (VarT 2 ==> VarT 0) ==> listOf (VarT 2) ==> VarT 0
254 , (,) "intercalate" . Forall [0,1] [ Context "`intercalate'" $ VarT 0 :<: appendable (VarT 1) ] $
255 VarT 0 ==> listOf (VarT 0) ==> VarT 0
256 , "zipWith" -:: (a ==> b ==> c) ==> listOf a ==> listOf b ==> listOf c
257 ] ++ map (numScheme (\n -> listOf n ==> n)) [ "sum", "product"
258 , "maximum", "minimum" ]
261 [ "maybe" -:: b ==> (a ==> b) ==> maybeOf a ==> b
262 , "isJust" -:: maybeOf a ==> bool
263 , "isNothing" -:: maybeOf a ==> bool
264 , "fromMaybe" -:: a ==> maybeOf a ==> a
265 , "consMaybe" -:: maybeOf a ==> listOf a ==> listOf a
266 , "catMaybes" -:: listOf (maybeOf a) ==> listOf a
267 , "catMaybes" -:: (a ==> maybeOf b) ==> listOf a ==> listOf b
270-------- Everything --------
272hints = mapM (\(n,s) -> (,) n `liftM` rescheme s) hs
273 where hs = concat [ funcs, lists, signals, math, bools, str2elem, textAttrs
274 , elements, directions, colors, lineTypes, shapes
275 , concreteSignals, casts, polyCasts, json, maybeFuncs
276 , positions, collages
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list