-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename identifiers according to issue #10
- Loading branch information
1 parent
dcfd9a6
commit 2f4e602
Showing
16 changed files
with
298 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
:set -fno-warn-unused-binds | ||
:set -fno-warn-unused-do-bind | ||
:set -fno-warn-type-defaults | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: course | ||
version: 0.0.7 | ||
version: 0.0.8 | ||
license: BSD3 | ||
license-file: etc/LICENCE | ||
author: Tony Morris <[email protected]> | ||
|
@@ -51,8 +51,8 @@ library | |
Intro.Validation | ||
IO.Interactive | ||
Monad.Compose | ||
Monad.Fuunctor | ||
Monad.Moonad | ||
Monad.Functor | ||
Monad.Monad | ||
Monad.State | ||
Monad.StateT | ||
Parser.JsonParser | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,82 @@ | ||
module Monad.Fuunctor where | ||
{-# LANGUAGE NoImplicitPrelude #-} | ||
|
||
module Monad.Functor where | ||
|
||
import Prelude(error, IO, fmap) | ||
import qualified Prelude as P | ||
import Intro.Id | ||
import Intro.Optional | ||
import Intro.Validation | ||
import Structure.List | ||
|
||
class Fuunctor f where | ||
fmaap :: (a -> b) -> f a -> f b | ||
class Functor f where | ||
fmap :: (a -> b) -> f a -> f b | ||
|
||
-- Exercise 1 | ||
-- Relative Difficulty: 1 | ||
-- | ||
-- | Maps a function on the Id functor. | ||
-- | ||
-- >>> fmaap (+1) (Id 2) | ||
-- >>> fmap (+1) (Id 2) | ||
-- Id 3 | ||
instance Fuunctor Id where | ||
fmaap = | ||
instance Functor Id where | ||
fmap = | ||
error "todo" | ||
|
||
-- Exercise 2 | ||
-- Relative Difficulty: 2 | ||
-- | ||
-- | Maps a function on the List functor. | ||
-- | ||
-- >>> fmaap (+1) Nil | ||
-- >>> fmap (+1) Nil | ||
-- [] | ||
-- | ||
-- >>> fmaap (+1) (1 :. 2 :. 3 :. Nil) | ||
-- >>> fmap (+1) (1 :. 2 :. 3 :. Nil) | ||
-- [2,3,4] | ||
instance Fuunctor List where | ||
fmaap = | ||
instance Functor List where | ||
fmap = | ||
error "todo" | ||
|
||
-- Exercise 3 | ||
-- Relative Difficulty: 2 | ||
-- | ||
-- | Maps a function on the Optional functor. | ||
-- | ||
-- >>> fmaap (+1) Empty | ||
-- >>> fmap (+1) Empty | ||
-- Empty | ||
-- | ||
-- >>> fmaap (+1) (Full 2) | ||
-- >>> fmap (+1) (Full 2) | ||
-- Full 3 | ||
instance Fuunctor Optional where | ||
fmaap = | ||
instance Functor Optional where | ||
fmap = | ||
error "todo" | ||
|
||
-- Exercise 4 | ||
-- Relative Difficulty: 3 | ||
-- | ||
-- | Maps a function on the reader ((->) t) functor. | ||
-- | ||
-- >>> fmaap (+1) (*2) 8 | ||
-- >>> fmap (+1) (*2) 8 | ||
-- 17 | ||
instance Fuunctor ((->) t) where | ||
fmaap = | ||
instance Functor ((->) t) where | ||
fmap = | ||
error "todo" | ||
|
||
-- Exercise 5 | ||
-- Relative Difficulty: 2 | ||
-- | ||
-- | Maps a function on an IO program. | ||
-- | ||
-- >>> fmaap reverse (putStr "hi" >> return "abc") | ||
-- >>> fmap reverse (putStr "hi" >> return "abc") | ||
-- hi"cba" | ||
instance Fuunctor IO where | ||
fmaap = | ||
instance Functor IO where | ||
fmap = | ||
error "todo" | ||
|
||
----------------------- | ||
-- SUPPORT LIBRARIES -- | ||
----------------------- | ||
|
||
instance Fuunctor [] where | ||
fmaap = | ||
fmap | ||
instance Functor [] where | ||
fmap = | ||
P.fmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package Monad | ||
|
||
import Intro._ | ||
import Structure._ | ||
|
||
trait Functor[F[_]] { | ||
def fmap[A, B](f: A => B): F[A] => F[B] | ||
|
||
// Provided as a synonym for `fmap` but with the arguments flipped. | ||
// This helps the type-inferencer. | ||
final def apply[A, B](a: F[A])(f: A => B): F[B] = | ||
fmap(f)(a) | ||
} | ||
|
||
object Functor { | ||
// Exercise 1 | ||
// Relative Difficulty: 1 | ||
implicit val IdFunctor: Functor[Id] = | ||
new Functor[Id] { | ||
def fmap[A, B](f: A => B) = | ||
sys.error("todo") | ||
} | ||
|
||
// Exercise 2 | ||
// Relative Difficulty: 2 | ||
implicit val ListFunctor: Functor[List] = | ||
new Functor[List] { | ||
def fmap[A, B](f: A => B) = | ||
sys.error("todo") | ||
} | ||
|
||
// Exercise 3 | ||
// Relative Difficulty: 2 | ||
implicit val OptionalFunctor: Functor[Optional] = | ||
new Functor[Optional] { | ||
def fmap[A, B](f: A => B) = | ||
sys.error("todo") | ||
} | ||
|
||
// Exercise 4 | ||
// Relative Difficulty: 3 | ||
implicit def Function1Functor[T]: Functor[({type l[a] = T => a})#l] = | ||
new Functor[({type l[a] = T => a})#l] { | ||
def fmap[A, B](f: A => B) = | ||
sys.error("todo") | ||
} | ||
|
||
/////////////////////// | ||
// SUPPORT LIBRARIES // | ||
/////////////////////// | ||
|
||
implicit val ScalaListFunctor: Functor[scala.List] = | ||
new Functor[scala.List] { | ||
def fmap[A, B](f: A => B) = | ||
_ map f | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.