O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a new project working-with-type-family with a simple stack template:
 stack new working-with-type-family simple
  1. Add a dependency on vector-space library in the build-depends sub-section of executable section:
 executable working-with-type-family
   hs-source-dirs:      src
   main-is:             Main.hs
   default-language:    Haskell2010
   build-depends:       base >= 4.7 && < 5
                      , vector-space
  1. Open src/Main.hs. We will be adding our source here.
  2. Define the module Main, and import Data.VectorSpace:
 module Main where

 import Data.VectorSpace
  1. Define vectors in three dimensions by using a tuple:
 diagonal :: (Double, Double, Double)
 diagonal = (1, 1, 1)
 xaxis :: (Double, Double, Double)
 xaxis = (1, 0, 0)
  1. Scale the diagonal vector, and take ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required