I am trying to write a function render
by using toPosition
with
render :: Dimensie -> Figure a -> [[a]]
But I can't figure out how. Could you propose a way to do this?
type Figure a = Pos -> a
type Pos = (Double, Double) -- (x, y)
chessboard :: Figure Bool
chessboard (x, y) = even (round x) == even (round y)
type Dimensie = (Int, Int)
render :: Dimensie -> Figure a -> [[a]]
render = undefined
toPosition :: Dimensie → (Int, Int) → Pos
toPosition d (x, y) = (fromIntegral x ∗ 2 / b − 1, 1 − fromIntegral y ∗ 2 / h)
where
b = fromIntegral (fst d − 1)
h = fromIntegral (snd d − 1)
And when I call it with
Figure> render (3,3) chessboard
it should give
[[True,False,True],[False,True,False],[True,False,True]]
And then I want to follow this up by writing a function that gives a certain character for a certain boolean value. It should display for example @
for True
and .
for False
boolChar :: Bool -> Char
boolChar = undefined
But how do I write this?
I don't get how to get a [[Bool]]
out of [[a]]
at the render
function, it keeps telling me that it couldn't match expected type ‘a’ with actual type ‘Bool’
and that ‘a’ is a rigid type variable bound by the type signature for:
and then it tells which line it went wrong.
So what do I write for render d (x,y) c = ....
to get it to display the asked outcome?