2014-05-05

Dependent Types in Scala

12:42 PM Posted by Yuriy Polyulya , ,
Dependent Types are types that depend on elements of other types. In other words it is a type that is predicated upon a value. An example is the type An of vectors of length n with components of type A and type An depends on the number n, or that A n is a family of types indexed by the number n.

"Dependent types == first-order logic" (c) Neelakantan Krishnaswami.

Motivation:
    To show way of dependent type difinition in Scala by path-dependent type and implicit parameters features.

Something like:
def mapTo[B](x : ListOf[1, Int]): (Int => B) => ListOf[1, B]
def mapTo[B](x : ListOf[2, Int]): (Int => B) => (Int => B) => ListOf[2, B]
def mapTo[B](x : ListOf[3, Int]): (Int => B) => (Int => B) => (Int => B) => ListOf[3, B]

2013-07-14

Functional Desing in Scala: Function definition

1:37 PM Posted by Yuriy Polyulya , ,

Methods and Functions can be defined in Scala with def and val keywords correspondingly.

Motivation:
    To define style of function definition in Scala. Show advantages and disadvantages of both way of function definition. Choose more natural style for functional design in Scala.

Proposal:
    Use anonymous functions instead of methods; always use curried function (Haskell style function); when deep parameters extraction needed - use PartialFunction. Make it possible to use composition and Functional Primitives (Function, Applicative, Monad) over functions.

Code:
  val flip: Int => State => State = 
    dy => {  // first argumetn
      // second argument with parameter extraction and guard conditions:
      case state @ State(Block(x, y), _, (w, h)) if(y > (h /2)) =>
        state copy (
          current = new Block(w - x, y + dy))

      // second argument without guard conditions:
      case state @ State(Block(x, y), _, _) =>
        state copy (
          current = new Block(x, y + dy))
   }

  // for types:
  case class Block(x: Int, y:Int)
  case class State(current: Block, wall: Seq[Block], gridSize: (Int, Int))



2013-04-15

Functional Design Primitives

9:49 PM Posted by Yuriy Polyulya , , ,
Design Primitives are the simples elements available in SW design.

Motivation:
     Goal of this post is define base set of functional design primitives (in Scala perspective) and define basic set of knowledge (categorised themes) necessary for understanding of Functional Design Principles and Patterns.

Plans:
     Will make wide description with Scala examples for all grops of primitives defined in this post.

2013-04-01

Chain call style with if-else injection in Scala

10:09 PM Posted by Yuriy Polyulya , ,
If-else injection in functions chain call style design.

Motivation:
    To make functions call chain continuous a conditional operator like: if or if-else sometimes needed. As far as Scala is not pure functional language and some functions in chain can be changed according to some local conditions or variables. So a goal of if-else operator injection is to make chain continuous without temporal variables usage.    It is applicable for Immutable Objects where forming function call chain is natural by design.

2012-12-28

Chain of Responsibility in Scala

Scala implementations of OOD behavior pattern: Chain of Responsibility.

Motivation:
    Chain of Responsibility pattern defines how to decouple senders and receivers, but with different trade-offs (passes a sender request along with chain of potential receivers).
    Show Scala possibilities in different implementation styles: from pure functional to object oriented with Scala features.