Using the grid coordinates from the previous video, you explore how to declare a cell data type and incorporate that into your code. This will also give you a good experience of refactoring code. You'll do this using Haskell's type system.
- [Instructor] In this video we're going to look…at fleshing out the Grid model.…So we're going to add parametrized type synonyms,…to create different types of Grid.…We're going to create a new data type called Cell,…and we're going to incorporate the coordinate grid…that we worked on in the last video into our program.…So we're going to carry on working within test.hs…very briefly just to look at a few more things…and then we'll incorporate this code…back into the main code base.…
So let's create a new data type called Cell.…So this will have a constructor called Cell,…and it will take a tuple of Integers,…and, of course, a Char.…And again, we'll add the deriving clause…of Eq, Ord, and Show,…so that we can compare it to other Cells…and display it on the screen.…So let's consider our coordinates Grid.…
And we saw that if we ran our new zipOverGrid function…with the cooridinates Grid that we returned…a tuple of coordinates and Chars…for each position in the Grid.…But now that we've created a data type for Cell…we can see that this might not be really…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Discovering Haskell with GHCI
- Haskell datatypes and functions
- Using higher order functions for data manipulation and code reuse
- Editing Haskell source code
- Creating a project with Stack
- Writing and conducting tests