Beef Welington
Veteran XV
So I'm taking this computer science class and the professor is basically insane, or just doesn't care. I have all the necessary prerequisites for this class, but he just seems to have decided that everybody should have come in already knowing how to program in Haskell, and is probably the least helpful person in the entire world.
On the first day, he gave us a worksheet to help us "learn" how to use Haskell. I have never had any experience with it before, and I have no clue what to do with this question:
"Define +, -, * for natural numbers. Define functions add, minus, and mult (each taking 2 Nat number variables) on the data type Nat = Z | S Nat deriving Show. Build functions nattoInt:Nat -> Int and buildNat:Int -> Nat to assist you."
I'm getting no help whatsoever on what this even means. I feel like it isn't very complicated, just some recursive definitions, but I have absolutely no experience with the syntax and semantics of Haskell.
I started reading Haskell tutorials, and got far enough to understand that I define the new data type by typing "data Nat = Z | S Nat deriving Show" (btw this is using Hugs mode, which I guess reads from a text file), but I have no idea of how to actually specify how this works. "Z" is a base case I think, "S" is supposed to be a successor, I get that, but I don't know how to define these things in the language.
Any help would be greatly appreciated.
On the first day, he gave us a worksheet to help us "learn" how to use Haskell. I have never had any experience with it before, and I have no clue what to do with this question:
"Define +, -, * for natural numbers. Define functions add, minus, and mult (each taking 2 Nat number variables) on the data type Nat = Z | S Nat deriving Show. Build functions nattoInt:Nat -> Int and buildNat:Int -> Nat to assist you."
I'm getting no help whatsoever on what this even means. I feel like it isn't very complicated, just some recursive definitions, but I have absolutely no experience with the syntax and semantics of Haskell.
I started reading Haskell tutorials, and got far enough to understand that I define the new data type by typing "data Nat = Z | S Nat deriving Show" (btw this is using Hugs mode, which I guess reads from a text file), but I have no idea of how to actually specify how this works. "Z" is a base case I think, "S" is supposed to be a successor, I get that, but I don't know how to define these things in the language.
Any help would be greatly appreciated.