mirror of https://gitlab.com/baco/l-c2019.git
feat(coding-style): Correct coding style
This commit is contained in:
parent
215938367b
commit
380c9bdabb
31
Lab1/Lab1.hs
31
Lab1/Lab1.hs
|
@ -1,20 +1,21 @@
|
|||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
|
||||
data Expr a = Const Int
|
||||
| Op (Expr Int)
|
||||
| Mas (Expr Int) (Expr Int)
|
||||
| Prod (Expr Int) (Expr Int)
|
||||
| Div (Expr Int) (Expr Int)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr Bool)
|
||||
| Conj (Expr Bool) (Expr Bool)
|
||||
deriving Show
|
||||
data Expr a
|
||||
= Const Int
|
||||
| Op (Expr Int)
|
||||
| Mas (Expr Int) (Expr Int)
|
||||
| Prod (Expr Int) (Expr Int)
|
||||
| Div (Expr Int) (Expr Int)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr Bool)
|
||||
| Conj (Expr Bool) (Expr Bool)
|
||||
deriving (Show)
|
||||
|
||||
class DomSem dom where
|
||||
sem :: Expr dom -> dom
|
||||
|
|
33
Lab2/Lab2.hs
33
Lab2/Lab2.hs
|
@ -1,21 +1,22 @@
|
|||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
|
||||
data Expr a = Const Int
|
||||
| Var Iden
|
||||
| Op (Expr a)
|
||||
| Mas (Expr a) (Expr a)
|
||||
| Prod (Expr a) (Expr a)
|
||||
| Div (Expr a) (Expr a)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr a)
|
||||
| Conj (Expr a) (Expr a)
|
||||
deriving Show
|
||||
data Expr a
|
||||
= Const Int
|
||||
| Var Iden
|
||||
| Op (Expr a)
|
||||
| Mas (Expr a) (Expr a)
|
||||
| Prod (Expr a) (Expr a)
|
||||
| Div (Expr a) (Expr a)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr a)
|
||||
| Conj (Expr a) (Expr a)
|
||||
deriving (Show)
|
||||
|
||||
class DomSem dom where
|
||||
sem :: Expr dom -> State -> dom
|
||||
|
|
46
Lab3/Lab3.hs
46
Lab3/Lab3.hs
|
@ -1,24 +1,25 @@
|
|||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
|
||||
data Expr a = Const Int
|
||||
| Var Iden
|
||||
| Op (Expr Int)
|
||||
| Mas (Expr Int) (Expr Int)
|
||||
| Prod (Expr Int) (Expr Int)
|
||||
| Div (Expr Int) (Expr Int)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr Bool)
|
||||
| Conj (Expr Bool) (Expr Bool)
|
||||
| Assign Iden (Expr Int)
|
||||
| If (Expr Bool) (Expr State) (Expr State)
|
||||
| Seq (Expr State) (Expr State)
|
||||
deriving Show
|
||||
data Expr a
|
||||
= Const Int
|
||||
| Var Iden
|
||||
| Op (Expr Int)
|
||||
| Mas (Expr Int) (Expr Int)
|
||||
| Prod (Expr Int) (Expr Int)
|
||||
| Div (Expr Int) (Expr Int)
|
||||
| AConst Bool
|
||||
| Equiv (Expr Int) (Expr Int)
|
||||
| Menor (Expr Int) (Expr Int)
|
||||
| Mayor (Expr Int) (Expr Int)
|
||||
| MenorEq (Expr Int) (Expr Int)
|
||||
| MayorEq (Expr Int) (Expr Int)
|
||||
| Not (Expr Bool)
|
||||
| Conj (Expr Bool) (Expr Bool)
|
||||
| Assign Iden (Expr Int)
|
||||
| If (Expr Bool) (Expr State) (Expr State)
|
||||
| Seq (Expr State) (Expr State)
|
||||
deriving (Show)
|
||||
|
||||
class DomSem dom where
|
||||
sem :: Expr dom -> State -> dom
|
||||
|
@ -42,9 +43,10 @@ instance DomSem Bool where
|
|||
|
||||
instance DomSem State where
|
||||
sem (Assign v e) σ = update σ v (sem e σ)
|
||||
sem (If b c c') σ = if sem b σ
|
||||
then sem c σ
|
||||
else sem c' σ
|
||||
sem (If b c c') σ =
|
||||
if sem b σ
|
||||
then sem c σ
|
||||
else sem c' σ
|
||||
sem (Seq c c') σ = sem c' (sem c σ)
|
||||
|
||||
type Iden = String
|
||||
|
|
14
Lab4/Lab4.hs
14
Lab4/Lab4.hs
|
@ -59,14 +59,16 @@ instance DomSem Σ' where
|
|||
sem (Assign v n) = \σ -> Normal (update σ v (sem n σ))
|
||||
sem (If b p p') = \σ ->
|
||||
if sem b σ
|
||||
then sem p σ
|
||||
else sem p' σ
|
||||
then sem p σ
|
||||
else sem p' σ
|
||||
sem (Seq c c') = \σ -> sem c' *. (sem c σ)
|
||||
sem (Catch c c') = \σ -> sem c' +. (sem c σ)
|
||||
sem (NewVar v e c) = \σ ->
|
||||
(\σ' -> update σ' v (σ v))
|
||||
(\σ' -> update σ' v (σ v))
|
||||
†. (sem c (update σ v (sem e σ)))
|
||||
sem (While b p) = fix f
|
||||
where f :: (Σ -> Σ') -> (Σ -> Σ')
|
||||
f w σ | sem b σ = w *. (sem p σ)
|
||||
| otherwise = Normal σ
|
||||
where
|
||||
f :: (Σ -> Σ') -> (Σ -> Σ')
|
||||
f w σ
|
||||
| sem b σ = w *. (sem p σ)
|
||||
| otherwise = Normal σ
|
||||
|
|
32
Lab5/Lab5.hs
32
Lab5/Lab5.hs
|
@ -51,43 +51,44 @@ instance DomSem Bool where
|
|||
(*.) :: (Σ -> Ω) -> Ω -> Ω
|
||||
(*.) f (Normal σ) = f σ
|
||||
(*.) _ (Abort σ) = Abort σ
|
||||
(*.) f (Out (n,ω)) = Out (n, f *. ω)
|
||||
(*.) f (Out (n, ω)) = Out (n, f *. ω)
|
||||
(*.) f (In g) = In ((f *.) . g)
|
||||
|
||||
(†.) :: (Σ -> Σ) -> Ω -> Ω
|
||||
(†.) f (Normal σ) = Normal $ f σ
|
||||
(†.) f (Abort σ) = Abort $ f σ
|
||||
(†.) f (Out (n,ω)) = Out (n, f †. ω)
|
||||
(†.) f (Out (n, ω)) = Out (n, f †. ω)
|
||||
(†.) f (In g) = In ((f †.) . g)
|
||||
|
||||
(+.) :: (Σ -> Ω) -> Ω -> Ω
|
||||
(+.) _ (Normal σ) = Normal σ
|
||||
(+.) f (Abort σ) = f σ
|
||||
(+.) f (Out (n,ω)) = Out (n, f +. ω)
|
||||
(+.) f (Out (n, ω)) = Out (n, f +. ω)
|
||||
(+.) f (In g) = In ((f +.) . g)
|
||||
|
||||
instance DomSem Ω where
|
||||
sem Skip = \σ -> Normal σ
|
||||
sem (NewVar v e c) = \σ ->
|
||||
(\σ' -> update σ' v (σ v))
|
||||
(\σ' -> update σ' v (σ v))
|
||||
†. (sem c (update σ v (sem e σ)))
|
||||
sem (Assign v n) = \σ -> Normal (update σ v (sem n σ))
|
||||
sem Fail = \σ -> Abort σ
|
||||
sem (Catch c c') = \σ -> sem c' +. (sem c σ)
|
||||
sem (While b p) = fix f
|
||||
where f :: (Σ -> Ω) -> (Σ -> Ω)
|
||||
f ω σ | sem b σ = ω *. (sem p σ)
|
||||
| otherwise = Normal σ
|
||||
where
|
||||
f :: (Σ -> Ω) -> (Σ -> Ω)
|
||||
f ω σ
|
||||
| sem b σ = ω *. (sem p σ)
|
||||
| otherwise = Normal σ
|
||||
sem (If b p p') = \σ ->
|
||||
if sem b σ
|
||||
then sem p σ
|
||||
else sem p' σ
|
||||
then sem p σ
|
||||
else sem p' σ
|
||||
sem (Seq c c') = \σ -> sem c' *. (sem c σ)
|
||||
sem (EMark e) = \σ -> Out (sem e σ, Normal σ)
|
||||
sem (QMark v) = \σ -> In (\n -> Normal (update σ v n))
|
||||
|
||||
-- | Funciones de evaluación de dom
|
||||
|
||||
class Eval dom where
|
||||
eval :: Expr dom -> Σ -> IO ()
|
||||
|
||||
|
@ -99,8 +100,9 @@ instance Eval Bool where
|
|||
|
||||
instance Eval Ω where
|
||||
eval e = unrollOmega . sem e
|
||||
where unrollOmega :: Ω -> IO ()
|
||||
unrollOmega (Normal σ) = return ()
|
||||
unrollOmega (Abort σ) = putStrLn "Abort"
|
||||
unrollOmega (Out (n, ω)) = putStrLn (show n) >> unrollOmega ω
|
||||
unrollOmega (In f) = getLine >>= unrollOmega . f . read
|
||||
where
|
||||
unrollOmega :: Ω -> IO ()
|
||||
unrollOmega (Normal σ) = return ()
|
||||
unrollOmega (Abort σ) = putStrLn "Abort"
|
||||
unrollOmega (Out (n, ω)) = putStrLn (show n) >> unrollOmega ω
|
||||
unrollOmega (In f) = getLine >>= unrollOmega . f . read
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Lab5
|
||||
|
||||
-- | Examples
|
||||
|
||||
{- * Example 1
|
||||
@
|
||||
while x < 10 do
|
||||
|
|
Loading…
Reference in New Issue