Scala as a Declarative Language

download Scala as a Declarative Language

If you can't read please download the document

Transcript of Scala as a Declarative Language

Introduction

Suresh B Velagapudi, Ph.DChief Technical OfficerMayera Software Solutions, LLC

FORTRAN is the first language. 1969 Btech IITMDid Eco and finance too. Ms and Ph.D in computer science. Intend going from 50% to 100%

Scalastic Warning

Prolog Technology for temporal reasoning in relational databases

In spite of Ph.D for the above research work, I love to code in and talk about scala.

I warn you up front thatYour present coding style is at risk.

That is my thesis title.

Scala as a Practical Declarative Language

Weltanschauung

Based on Peace, Practicality and ProductivityNot on Power, Pride, Prejudice or Prosperity etc.

In A Nutshell

Declarative Programming Style in Scala makes software product development from Proof-of-Concept to Deployment enjoyable.

Enjoy

Abbreviations

MOD Martin ODerskyDOS Designer Of Scala

SBE Scala By ExampleASS96 Abelson Sussman SussmanMIL78 Milner

COW Check Out Wikipedia

DOP A Discipline Of Programming 1976

Ramanujan

scala> for {hardyTaxi Nil case x :: xs => reverse(xs) ::: List(x)}

//SBE page 75def reverse: List[A] = ((Nil: List[A]) /: this) {(xs, x) => x :: xs}

//Is Tail Recursive Reverse Possible?

Tail Recursive Reverse

def reverse[T](l: List[T]): List[T] = { def reverseR(result: List[T], curList: List[T]): List[T] = curList match { case Nil => result case h :: tail => reverseR(h :: result, tail) } reverseR(Nil, l) }

Sample Conversation with ELIZA

I am unhappy.>> How long have you been unhappy?Six months. Can you help me.>> What makes you think I help you?You remind me of my father and brother>>Please tell me more about father.I like teasing father.>>Does anyone else in your family like teasing father?No, only me.>> Please go on

ELIZA in Scala

def response(stimulus : List[String]) : Unit = stimulus match {case List("i","am", x) => println("How long have you been" + x+ "?")case List(x, "you", y, "me") => println("What makes you think I " +y+" you?")case List("i","feel", x) => println("Do you often feel that way?")case List("i", "like", x) => println("Does any one else in your family like " + x +" ?") case _ => println("Please Go On")}

Machine Learning

Suppose ELIZA wants to improve. Weka switched to java from prolog.SWeka will be in Scala.

Future of Scala

Pessimistic Scenario:Functional freaks and java addicts fight to finishto scare away all scala enthusiasts.

Optimistic Scenario: Complete Domination of the entire computing scene

Most likely scenario: Solid apps come up.Steady impressive growth for next decade.

Pollak's cpp Principle

Each morning that I sit down at the keyboard and start coding Scala, I get afeeling of calm, peace, and power. I know that Im going to have another day of taking theideas in my head and reducing them to a running computer program that will be fast andlow in defects.

Pollak

But most importantly, Scala taught me to program and reason about programmingdifferently. I stopped thinking in terms of allocating buffers, structs, and objects, and ofchanging those pieces of memory. Instead, I learned to think about most of my programsas transforming input to output. This change in thinking has lead (sic) to lower defect rates,more modular code, and more testable code.

Tony Hoare in QCON 2009

One day... Software will be the most reliable component Of every product which contains it. Software engineering will be the most Dependable of all engineering professions. Because of the successful interplay of research into the science of programming and the engineering of software

I have a dream

One day.....My fellow scalastics' programs will be judged not by the colorful confusion of syntax but by the content of the character sequences with declarative semantics.

Remember SURESH

Semantics independent of execution is the aim.

Universal quantification is for stating facts and rules. Recursion is natural and efficient with TRO Call.

Extensive use of pattern matching is desirable.

Static typing of generics avoids awful defects.

Higher order functions help declarative programming.

The End

Thank You