mirror of
https://github.com/iritmaximus/haskell.git
synced 2026-10-12 19:13:39 +03:00
5a ex5
This commit is contained in:
+6
-6
@@ -97,27 +97,27 @@ setAge age (Person _ name) = Person age name
|
|||||||
-- getY (up (up origin)) ==> 2
|
-- getY (up (up origin)) ==> 2
|
||||||
-- getX (up (right origin)) ==> 1
|
-- getX (up (right origin)) ==> 1
|
||||||
|
|
||||||
data Position = PositionUndefined
|
data Position = Position Int Int
|
||||||
|
|
||||||
-- origin is a Position value with x and y set to 0
|
-- origin is a Position value with x and y set to 0
|
||||||
origin :: Position
|
origin :: Position
|
||||||
origin = todo
|
origin = Position 0 0
|
||||||
|
|
||||||
-- getX returns the x of a Position
|
-- getX returns the x of a Position
|
||||||
getX :: Position -> Int
|
getX :: Position -> Int
|
||||||
getX = todo
|
getX (Position x _) = x
|
||||||
|
|
||||||
-- getY returns the y of a position
|
-- getY returns the y of a position
|
||||||
getY :: Position -> Int
|
getY :: Position -> Int
|
||||||
getY = todo
|
getY (Position _ y) = y
|
||||||
|
|
||||||
-- up increases the y value of a position by one
|
-- up increases the y value of a position by one
|
||||||
up :: Position -> Position
|
up :: Position -> Position
|
||||||
up = todo
|
up (Position x y) = Position x (y+1)
|
||||||
|
|
||||||
-- right increases the x value of a position by one
|
-- right increases the x value of a position by one
|
||||||
right :: Position -> Position
|
right :: Position -> Position
|
||||||
right = todo
|
right (Position x y) = Position (x+1) y
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- Ex 6: Here's a datatype that represents a student. A student can
|
-- Ex 6: Here's a datatype that represents a student. A student can
|
||||||
|
|||||||
Reference in New Issue
Block a user