|
Scala example source code file (Arrows.scala)
The Scala Arrows.scala source codepackage scala.tools.scalap package scalax package rules trait Arrows extends UnitFunctors { type Arr[-A, +B] <: Arrow[A, B] type M[+B] = Arr[Nothing, B] def arrow[A, B](f : A => B) : Arr[A, B] def diag[A] = arrow[A, (A, A)] { a => (a, a) } override def unit[B](b : => B) : M[B] = arrow { any : Any => b } trait Arrow[-A, +B] extends Functor[B] { this : Arr[A, B] => def map[C](f : B => C) = comp(arrow(f)) def comp[C](bc : => Arr[B, C]) : Arr[A, C] def fst[C] : Arr[(A, C), (B, C)] } } trait ApplicativeArrows extends Arrows { type Arr[-A, +B] <: ApplicativeArrow[A, B] def app[A, B] : Arr[(Arr[A, B], A), B] trait ApplicativeArrow[-A, +B] extends Arrow[A, B] { self : Arr[A, B] => def flatMap[SubA <: A, C](f : B => Arr[SubA, C]) : Arr[SubA, C] = diag[SubA].comp(map(f).fst[SubA]).comp(app[SubA, C]) } } trait ArrowMonads extends ApplicativeArrows with Monads { type Arr[-A, +B] <: ApplicativeArrow[A, B] with Monad[B] override def unit[A](a : => A) : M[A] = arrow[Unit, A](Unit => a) } Other Scala examples (source code examples)Here is a short list of links related to this Scala Arrows.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.