@@ -48,6 +48,12 @@ floatToInt x = foreign_ tyInt "floatToInt" [(x, tyFloat)]
4848floatExp x = foreign_ tyFloat "exp" [(x, tyFloat)]
4949floatLog x = foreign_ tyFloat "log" [(x, tyFloat)]
5050
51+strIndex x i = foreign_ tyChar "strIndex" [(x, tyString), (i, tyInt)]
52+strHead x = foreign_ tyChar "strHead" [(x, tyString)]
53+strTail x = foreign_ tyString "strTail" [(x, tyString)]
54+strCons x xs = foreign_ tyString "strCons" [(x, tyChar), (xs, tyString)]
55+strRev x = foreign_ tyString "strrev" [(x, tyString)]
56+
5157primitives =
5258 -- operators
5359 [Prim (UN "prim__addInt") (ty [IType, IType] IType) 2 (iBin (+))
@@ -128,7 +134,17 @@ primitives =
128134 Prim (UN "prim__floatExp") (ty [FlType] FlType) 1 (p_floatExp)
129135 ([E.name "x"], floatExp (fun "x")),
130136 Prim (UN "prim__floatLog") (ty [FlType] FlType) 1 (p_floatLog)
131− ([E.name "x"], floatLog (fun "x"))
137+ ([E.name "x"], floatLog (fun "x")),
138+ Prim (UN "prim__strHead") (ty [StrType] ChType) 1 (p_strHead)
139+ ([E.name "x"], strHead (fun "x")),
140+ Prim (UN "prim__strTail") (ty [StrType] StrType) 1 (p_strTail)
141+ ([E.name "x"], strTail (fun "x")),
142+ Prim (UN "prim__strCons") (ty [ChType, StrType] StrType) 2 (p_strCons)
143+ ([E.name "x", E.name "xs"], strCons (fun "x") (fun "xs")),
144+ Prim (UN "prim__strIndex") (ty [StrType, IType] ChType) 2 (p_strIndex)
145+ ([E.name "x", E.name "i"], strIndex (fun "x") (fun "i")),
146+ Prim (UN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
147+ ([E.name "x"], strRev (fun "x"))
132148 ]
133149
134150iBin op [VConstant (I x), VConstant (I y)] = Just $ VConstant (I (op x y))
@@ -182,6 +198,18 @@ p_floatExp _ = Nothing
182198p_floatLog [VConstant (Fl x)] = Just $ VConstant (Fl (log x))
183199p_floatLog _ = Nothing
184200
201+p_strHead [VConstant (Str (x:xs))] = Just $ VConstant (Ch x)
202+p_strHead _ = Nothing
203+p_strTail [VConstant (Str (x:xs))] = Just $ VConstant (Str xs)
204+p_strTail _ = Nothing
205+p_strIndex [VConstant (Str xs), VConstant (I i)]
206+ | i < length xs = Just $ VConstant (Ch (xs!!i))
207+p_strIndex _ = Nothing
208+p_strCons [VConstant (Ch x), VConstant (Str xs)] = Just $ VConstant (Str (x:xs))
209+p_strCons _ = Nothing
210+p_strRev [VConstant (Str xs)] = Just $ VConstant (Str (reverse xs))
211+p_strRev _ = Nothing
212+
185213elabPrim :: Prim -> Idris ()
186214elabPrim (Prim n ty i def epic)
187215 = do updateContext (addOperator n ty i def)