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. Open src/Main.hs for editing.
  2. Add a new data type Func a b to represent the function f :: a -> b:
        newtype Func a b = Func (a -> b)
  1. Add a compose function. The compose function takes in two functions and  composes them together by giving an output of the first function to the next one:
       compose :: Func a b -> Func b c -> Func a c       compose (Func f) (Func g) = Func (g . f)
  1. Now, add a apply function; this takes our data type Func and applies an argument to it:
        apply :: Func a b -> a -> b        apply (Func f) a = f a
  1. Now, define a data type called Fix; it takes a function as an argument and tries to recursively define it by applying itself to the function:
        newtype Fix f = Fix (f (Fix f))
  1. Now, define a type Ghost; it takes ...

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