0

I am currently trying to access an element from a 2d Vector declared as such:

data Board = FullBoard Int Int
:t FullBoard
FullBoard :: Int -> Int -> Board

(FullBoard x y)

If I am correct, the two Ints Are the size of the board, in this 2d Vector. My issue is that I cannot seem to find a way to access the (x, y) element and changing the data that is currently stored as 0 in a nested tuple. I have tried using several things including using the lens library, however I have had no luck with a^._2 or similar getter functions.

Any help is appreciated!

  • What 'Vector' are you referring to? Which library and module? What is the full code required for `a` to compile (or even scope check)? – user2407038 Oct 12 '15 at 03:14
  • Allow me to edit my question. –  Oct 12 '15 at 03:20
  • Also, I am only trying to make a 2D Vector which stores the data 0 or 1. –  Oct 12 '15 at 03:47
  • 2
    You can access the values inside simply by pattern matching, for example `f (FullBoard x y) = x + y`. You cannot use lens functions without creating lenses for your datatypes, or generating them automatically with template haskell. You'll have to look to lens tutorials for that. The simplest thing you can do is `data V2 = V2 { v2_a, v2_b :: a }`; then you have `v2_a, v2_b :: V2 a -> a` which get the two coordinates; and you have `V2 True False :: V2 Bool` to represent 2D vectors which store only 0 or 1 at each coordinate. – user2407038 Oct 12 '15 at 04:05
  • Thanks, that helped a lot! –  Oct 12 '15 at 04:23

0 Answers0