Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 2.00 KB  |  hits: 15  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
2.
4.   def flatMap[A, B](a: M[A], f: A => M[B]): M[B]
5.   def unital[A](a: A): M[A]
6. }
7.
8. // A simple data type, which turns out to satisfy the above trait
9. case class Inter[A](f: Int => A)
10.
11. // So does this.
12. case class Identity[A](a: A)
13.
17.     def flatMap[A, B](a: List[A], f: A => List[B]): List[B] = a flatMap f
18.     def unital[A](a: A): List[A] = List(a)
19.   }
20.
22.     def flatMap[A, B](a: Option[A], f: A => Option[B]) = a flatMap f
23.     def unital[A](a: A): Option[A] = Option(a)
24.   }
25.
26.   // 4. Replace error("todo") with an implementation
28.
29.   // 5. Replace error("todo") with an implementation
31. }
32.
34.   // 6. Replace error("todo") with an implementation
35.   def sequence[M[_], A](as: List[M[A]], m: Monad[M]): M[List[A]] =
36.     error("todo")
37.
38.   // 7. Replace error("todo") with an implementation
39.   def fmap[M[_], A, B](a: M[A], f: A => B, m: Monad[M]): M[B] =
40.     error("todo")
41.
42.   // 8. Replace error("todo") with an implementation
43.   def flatten[M[_], A](a: M[M[A]], m: Monad[M]): M[A] =
44.     error("todo")
45.
46.   // 9. Replace error("todo") with an implementation
47.   def apply[M[_], A, B](f: M[A => B], a: M[A], m: Monad[M]): M[B] =
48.     error("todo")
49.
50.   // 10. Replace error("todo") with an implementation
51.   def filterM[M[_], A](f: A => M[Boolean], as: List[A]
52.     , m: Monad[M]): M[List[A]] =
53.     error("todo")
54.
55.   // 11. Replace error("todo") with an implementation
56.   def replicateM[M[_], A](n: Int, a: M[A], m: Monad[M]): M[List[A]] =
57.     error("todo: flatMap n times to produce a list")
58.
59.   // 12. Replace error("todo") with an implementation
60.   def lift2[M[_], A, B, C](f: (A, B) => C, a: M[A], b: M[B]
61.     , m: Monad[M]): M[C] =
62.     error("todo")
63.
64.   // lift3, lift4, etc. Interesting question: Can we have liftN?
65. }