Sunday, April 23, 2017

Haskell

Definition

  • Is truly functional strongly typed, lazily executed expressive high level programming language.
  • There are no for loops, there are no while loops or go-to and no variables
  • There are constants like variables
  • Pure functional programming
  • Values and functions are same in Haskell
  • Syntax is easy

Compiler used by Haskell

GHC :Glassgow Haskell compiler

What is functional programming?

  • No assignment statements
  • No variables
  • Once given a value never change
  • No side effects at all

"Functional programmer sounds like a monk, denying himself the pleasure s of life in the hope that it would make him virtuous."

Why functional programming matters?

What procedural programming, dependency injection, actor model, Micro services and clean architecture have in common ?
ans :We strive from modularity
We give an input and we get an output
Testing is easier and tests are cleaner
There is no concept of time
We can reason about our code with ease
Just follow steps

An interactive program is a pure function that takes the current state of the world as it's arg and produces a modified world as a result
Don't try to track real world state in your code.instead take it's argument, since only the world knows what state it's In.

Fun with functions

  • Helloworld= " Hello World"
  • Function without parameter is called definition
  • Function name must start with small letter

Helloworld
london u = "London " ++  u
london : : [char] -> [char]
london " baby "

Note : We do not have to specify the type
ex:

a = 5 + 4
In the above example haskell knows that a is a number.It is intelligent to figure that.

No comments:

Post a Comment