Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Please convert this Scala code to Python code: /* Scala data type definitions similar to the Haskell definitions Building the DSL */ // data Platter

Please convert this Scala code to Python code:

/* Scala data type definitions similar to the Haskell definitions "Building the DSL" */

// data Platter = Platter [Sandwich] // deriving Show

case class Platter(platter: List[Sandwich])

// data Sandwich = Sandwich [Layer] // deriving Show

case class Sandwich(sandwich: List[Layer])

// data Layer = Bread Bread | Meat Meat | // Cheese Cheese | Vegetable Vegetable | // Condiment Condiment // deriving (Eq,Show)

sealed trait Layer

// data Bread = White | Wheat | Rye // deriving (Eq,Show)

sealed trait Bread extends Layer case object White extends Bread case object Wheat extends Bread case object Rye extends Bread

// data Meat = Turkey | Chicken | Ham | RoastBeef | Tofu // deriving (Eq,Show)

sealed trait Meat extends Layer case object Turkey extends Meat case object Chicken extends Meat case object Ham extends Meat case object RoastBeef extends Meat case object Tofu extends Meat

// data Cheese = American | Swiss | Jack | Cheddar // deriving (Eq,Show)

sealed trait Cheese extends Layer case object American extends Cheese case object Swiss extends Cheese case object Jack extends Cheese case object Cheddar extends Cheese

// data Vegetable = Tomato | Onion | Lettuce | BellPepper // deriving (Eq,Show)

sealed trait Vegetable extends Layer case object Tomato extends Vegetable case object Onion extends Vegetable case object Lettuce extends Vegetable case object BellPepper extends Vegetable

// data Condiment = Mayo | Mustard | Ketchup | Relish | Tabasco // deriving (Eq,Show)

sealed trait Condiment extends Layer case object Mayo extends Condiment case object Mustard extends Condiment case object Ketchup extends Condiment case object Relish extends Condiment case object Tabasco extends Condiment

// Haskell function type signatures for "Building the DSL" // newSandwich :: Bread -> Sandwich // addLayer :: Sandwich -> Layer -> Sandwich // newPlatter :: Platter // addSandwich :: Platter -> Sandwich -> Platter

// Scala function type signatures for "Building the DSL" // def newSandwich(b: Bread): Sandwich // def addLayer(s: Sandwich)(x: Layer): Sandwich // def newPlatter: Platter // def addSandwich(p: Platter)(s: Sandwich): Platter

/* Scala data type definitions similar to the Haskell definitions in "Compiling the Program for the SueChef Controller" */

// data SandwichOp = StartSandwich | FinishSandwich | // AddBread Bread | AddMeat Meat | // AddCheese Cheese | AddVegetable Vegetable | // AddCondiment Condiment | // StartPlatter | MoveToPlatter | FinishPlatter // deriving (Eq, Show)

sealed trait SandwichOp case object StartSandwich extends SandwichOp case object FinishSandwich extends SandwichOp case class AddBread(bread: Bread) extends SandwichOp case class AddMeat(meat: Meat) extends SandwichOp case class AddCheese(cheese: Cheese) extends SandwichOp case class AddVegetable(vegetable: Vegetable) extends SandwichOp case class AddCondiment(condiment: Condiment) extends SandwichOp case object StartPlatter extends SandwichOp case object MoveToPlatter extends SandwichOp case object FinishPlatter extends SandwichOp

// data Program = Program [SandwichOp] // deriving Show

case class Program(program: List[SandwichOp])

// val prices = List( // (White,20),(Wheat,30),(Rye,30), // (Turkey,100),(Chicken,80),(Ham,120),(RoastBeef,140),(Tofu,50), // (American,50),(Swiss,60),(Jack,60),(Cheddar,60), // (Tomato,25),(Onion,20),(Lettuce,20),(BellPepper,25), // (Mayo,5),(Mustard,4),(Ketchup,4),(Relish,10),(Tabasco,5) // )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions