mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 13:00:08 +00:00
IT'S WORKIIING! IT'S WORKINGGG
This commit is contained in:
@@ -115,6 +115,7 @@ data CardinalityCoercion =
|
||||
| MakeObject2MaybeCoercion {fromCardinality :: Cardinality, toCardinality :: Cardinality}
|
||||
| MakeObject2ListCoercion {fromCardinality :: Cardinality, toCardinality :: Cardinality}
|
||||
| MakeOneOfCoercion {toCardinality :: Cardinality}
|
||||
| MakeMaybe2ObjectCoercion {toCardinality :: Cardinality}
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- |Used to handle polymorphism in Rosetta
|
||||
|
||||
@@ -51,7 +51,7 @@ printExpression (ExplicitFunction "and" args returnCoerce) = printCoercion (snd
|
||||
printExpression (ExplicitFunction "or" args returnCoerce) = printCoercion (snd $ head args) (printExpression (fst $ head args)) <+> "||" <+> printCoercion (snd $ head $ tail args) (printExpression (fst $ head $ tail args))
|
||||
printExpression (ExplicitFunction name args returnCoerce) =
|
||||
if null printedArgs then pretty (uncapitalize name)
|
||||
else pretty (uncapitalize name) <+> printCoercion returnCoerce (hsep (map (enclose "(" ")") printedArgs))
|
||||
else pretty (uncapitalize name) <+> (hsep (map (enclose "(" ")") printedArgs))
|
||||
where printedArgs = zipWith printCoercion [c | (e,c) <- args] [printExpression e | (e, c) <- args]
|
||||
printExpression (ExplicitIfSimple cond thenBlock returnCoercion) =
|
||||
printIf
|
||||
@@ -101,7 +101,8 @@ printCardinalityCoercion (MakeListCardinalityCoercion _ _) d = d
|
||||
printCardinalityCoercion (MakeNothing2MaybeCoercion _ _) d = "Nothing"
|
||||
printCardinalityCoercion (MakeNothing2ListCoercion _ _) d = "[]"
|
||||
printCardinalityCoercion (MakeMaybe2ListCoercion _ _) d = "maybeToList" <+> enclose "(" ")" d
|
||||
printCardinalityCoercion (MakeObject2MaybeCoercion _ _) d = "fromJust" <+> enclose "(" ")" d
|
||||
printCardinalityCoercion (MakeObject2MaybeCoercion _ _) d = "Just" <+> enclose "(" ")" d
|
||||
printCardinalityCoercion (MakeMaybe2ObjectCoercion _) d = "fromJust" <+> enclose "(" ")" d
|
||||
printCardinalityCoercion (MakeObject2ListCoercion _ _) d = "[" <> d <> "]"
|
||||
printCardinalityCoercion (MakeOneOfCoercion _) d = d
|
||||
|
||||
|
||||
@@ -166,13 +166,18 @@ checkExpression defT symbolMap (PathExpression ex1 (Variable b)) =
|
||||
Left err -> Left err
|
||||
Right exp1 -> case findAttributeTypeRec defT b type1 of
|
||||
Left err -> Left $ UndefinedVariable $ show (typeName type1) ++ " -> " ++ b
|
||||
Right exp2 -> case Bounds(1, 1) `cardinalityIncluded` crd1 of
|
||||
Right exp2 -> case cardC of
|
||||
Left err -> Left $ PathExpressionOnList (show ex1)
|
||||
Right c -> if MakeCondition Nothing (Keyword "one-of") `elem` conditions (typeFromExpression exp1)
|
||||
then Right $ ExplicitPath (changeCoercion exp1 ((returnCoercion exp1){cardinalityCoercion = c})) (changeCoercion exp2 exp2C) exp2C
|
||||
else Right $ ExplicitPath (changeCoercion exp1 ((returnCoercion exp1){cardinalityCoercion = c})) exp2 (returnCoercion exp2)
|
||||
where
|
||||
exp2C = MakeCoercion (typeCoercion $ returnCoercion exp2) (MakeOneOfCoercion (Bounds (1,1)))
|
||||
where
|
||||
exp2C = MakeCoercion (typeCoercion $ returnCoercion exp2) (MakeOneOfCoercion (Bounds (1,1)))
|
||||
cardC = case crd1 of
|
||||
Bounds (1, 1) -> Right $ MakeCardinalityIdCoercion crd1
|
||||
Bounds (0, 1) -> Right $ MakeMaybe2ObjectCoercion (Bounds (1, 1))
|
||||
_ -> Left $ PathExpressionOnList (show ex1)
|
||||
|
||||
where
|
||||
type1 = typeFromExpression exp1
|
||||
crd1 = toCardinality $ cardinalityCoercion $ returnCoercion exp1
|
||||
|
||||
Reference in New Issue
Block a user