Address issues with unify's case tree in idris
Clean up some stuff in prelude Add parser for where
This commit is contained in:
@@ -109,6 +109,13 @@ instance Functor Maybe where
|
||||
map f Nothing = Nothing
|
||||
map f (Just a) = Just (f a)
|
||||
|
||||
-- TODO this probably should depend on / entail Functor
|
||||
infixl 3 _<*>_
|
||||
class Applicative (f : U → U) where
|
||||
-- appIsFunctor : Functor f
|
||||
return : {a} → a → f a
|
||||
_<*>_ : {a b} -> f (a → b) → f a → f b
|
||||
|
||||
infixr 2 _<|>_
|
||||
class Alternative (m : U → U) where
|
||||
_<|>_ : {a} → m a → m a → m a
|
||||
@@ -185,9 +192,17 @@ pfunc alen : {a : U} -> Array a -> Int := "(a,arr) => arr.length"
|
||||
pfunc aget : {a : U} -> Array a -> Int -> a := "(a, arr, ix) => arr[ix]"
|
||||
pfunc aempty : {a : U} -> Unit -> Array a := "() => []"
|
||||
|
||||
|
||||
-- TODO represent Nat as number at runtime
|
||||
pfunc natToInt : Nat -> Int := "(n) => {
|
||||
let rval = 0
|
||||
while (n.tag === 'S') {
|
||||
n = n.h0
|
||||
rval++
|
||||
}
|
||||
return rval
|
||||
}"
|
||||
pfunc fastConcat : List String → String := "(xs) => listToArray(undefined, xs).join('')"
|
||||
pfunc replicate : Nat -> Char → String := "() => abort('FIXME replicate')"
|
||||
pfunc replicate : Nat -> Char → String := "(n,c) => c.repeat(natToInt(n))"
|
||||
|
||||
-- I don't want to use an empty type because it would be a proof of void
|
||||
ptype World
|
||||
@@ -203,7 +218,10 @@ instance Monad IO where
|
||||
MkIORes a w => mab a w
|
||||
pure a = \ w => MkIORes a w
|
||||
|
||||
pfunc putStrLn : String -> IO Unit := "(s) => (w) => console.log(s)"
|
||||
pfunc putStrLn : String -> IO Unit := "(s) => (w) => {
|
||||
console.log(s)
|
||||
return MkIORes(Unit,MkUnit,w)
|
||||
}"
|
||||
|
||||
class Show a where
|
||||
show : a → String
|
||||
|
||||
@@ -86,8 +86,8 @@ pretty {{MkPretty p}} x = p x
|
||||
render : Nat -> Doc -> String
|
||||
render w x = layout (best w Z x) Lin
|
||||
|
||||
SemigroupDoc : Semigroup Doc
|
||||
SemigroupDoc = MkSemi (\ x y => Seq x (Seq (Text " ") y))
|
||||
instance Semigroup Doc where
|
||||
x <+> y = Seq x (Seq (Text " ") y)
|
||||
|
||||
-- Match System.File so we don't get warnings
|
||||
|
||||
@@ -100,9 +100,8 @@ text = Text
|
||||
nest : Nat -> Doc -> Doc
|
||||
nest = Nest
|
||||
|
||||
infixl 7 _++_
|
||||
_++_ : Doc -> Doc -> Doc
|
||||
x ++ y = Seq x y
|
||||
instance Concat Doc where
|
||||
x ++ y = Seq x y
|
||||
|
||||
infixl 5 _</>_
|
||||
_</>_ : Doc -> Doc -> Doc
|
||||
|
||||
@@ -17,3 +17,4 @@ foo = render fifty doc
|
||||
main : IO Unit
|
||||
main = do
|
||||
putStrLn foo
|
||||
putStrLn $ replicate five 'x'
|
||||
|
||||
Reference in New Issue
Block a user