Guest User

Untitled

a guest
Jan 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. import scalaz._
  2. import Scalaz._
  3.  
  4. type List[A] = Forall[({type f[B] = ((A, B) => B, B) => B})#f]
  5.  
  6. val nil: Forall[List] = new Forall[List] {
  7. def apply[A] = new List[A] {
  8. def apply[B] = (c, n) => n
  9. }
  10. }
  11.  
  12. val cons: Forall[({type f[x] = (x, List[x]) => List[x]})#f] =
  13. new Forall[({type f[x] = (x, List[x]) => List[x]})#f] {
  14. def apply[A] = (h, t) => new List[A] {
  15. def apply[B] = (c, n) => c(h, t.apply(c, n))
  16. }
  17. }
  18.  
  19. def map[A, B](f: A => B, as: List[A]): List[B] =
  20. as.apply[List[B]]((h, t) => cons.apply(f(h), t), nil.apply[B])
Add Comment
Please, Sign In to add comment