Commit 3996b7cc authored by bbr's avatar bbr
Browse files

new primitive types and error

- added fail constructor to primitive type wrapper
- changed prim_error and failed
- conversion string<->string'
parent a64a0dc2
......@@ -24,10 +24,16 @@ f $## x = incSteps (f x)
type String' = List Char'
instance (Eq a,Show a) => StrictCurry (Maybe a) where
underscore = Nothing
showCons Nothing = consUnderscore
showCons (Just a) = consTerm (Prelude.show a) []
data Prim a = Prim a
| PrimFailed String
| PrimUnderscore deriving (Show,Eq)
instance (Eq a,Show a) => StrictCurry (Prim a) where
underscore = PrimUnderscore
failure = PrimFailed
showCons PrimUnderscore = consUnderscore
showCons (PrimFailed s) = consFailed s
showCons (Prim a) = consTerm (Prelude.show a) []
instance Show (IO a) where
show x = "IO"
......@@ -35,16 +41,16 @@ instance Eq (IO a) where
_==_ = Prelude.error ""
prim_error :: StrictCurry a => String' -> Step a
prim_error x = return' underscore
prim_error x = return' (failure (string'ToString x))
prim_failed :: StrictCurry a => Step a
prim_failed = return' underscore
prim_failed = return' (failure "failed")
prim_ord :: Char' -> Step Int'
prim_ord (Just c) = incSteps (return' (intToInt' (Char.ord c)))
prim_ord (Prim c) = incSteps (return' (intToInt' (Char.ord c)))
prim_chr :: Int' -> Step Char'
prim_chr i = return' (Just (Char.chr (int'ToInt i)))
prim_chr i = return' (Prim (Char.chr (int'ToInt i)))
(===) :: StrictCurry a => a -> a -> Step Bool'
x === y = return' (boolToBool' (x Prelude.== y))
......@@ -74,7 +80,7 @@ prim_appendFile _ = Prelude.error "" --return ()
catchFail = Prelude.error ""
prim_show :: StrictCurry a => a -> Step String'
prim_show a = return' (listToList' (Prelude.map Just (Prelude.show a)))
prim_show a = return' (stringToString' (Prelude.show a))
getSearchTree x = Prelude.error ""
......@@ -133,6 +139,12 @@ list'ToList :: List a -> [a]
list'ToList List = []
list'ToList (Cons x xs) = x : list'ToList xs
string'ToString :: String' -> String
string'ToString x = Prelude.map (\ (Prim a) -> a) (list'ToList x)
stringToString' :: String -> String'
stringToString' x = listToList' (Prelude.map Prim x)
------------------------------------------------------------------------------------------
-- end of include
------------------------------------------------------------------------------------------
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment