Autre implémentation naïve en Haskell
La même chose sans les records, du coup on crée la fonction
-- Module Skouares
data Square = Square { x :: Int
, y :: Int
, user :: String
} deriving (Show)
square :: Int -> Int -> String -> Square
square x y user = Square {x=x,y=y,user=user}
squareX :: Int -> [Square]
squareX cx = filter ((cx==).x) squares
squareXY :: Int -> Int -> [Square]
squareXY cx cy = filter (((cx,cy)==).xy) squares
xy :: Square -> (Int, Int)
xy a = (x a, y a)
squares :: [Square]
squares = [ square 2 2 "oxman"
, square 4 6 "oxman"
, square 4 7 "Sephi-Chan"
, square 2 7 "Sephi-Chan"
, square 4 4 "oxman"
, square 2 7 "Sephi-Chan"
]
La même chose sans les records, du coup on crée la fonction
x
comme accessor en plus-- Module Skouares
data Square = Square Int Int String deriving (Show)
squareX :: Int -> [Square]
squareX cx = filter ((cx==).x) squares
squareXY :: Int -> Int -> [Square]
squareXY cx cy = filter (((cx,cy)==).xy) squares
xy :: Square -> (Int, Int)
xy (Square x y u) = (x, y)
x :: Square -> Int
x (Square x y u) = x
squares :: [Square]
squares = [ Square 2 2 "oxman"
, Square 4 6 "oxman"
, Square 4 7 "Sephi-Chan"
, Square 2 7 "Sephi-Chan"
, Square 4 4 "oxman"
, Square 2 7 "Sephi-Chan"
]