-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add blog post on Functional Programming #85
base: master
Are you sure you want to change the base?
Conversation
@parvmor see if you can add something! |
"In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data." | ||
Didn't get it? No problem! Continue reading and at the end, atleast you will get to know what it is all about. | ||
|
||
Actually Functional Programming is much about abstraction and mathematical concepts. And that is what acts as an hindrance for programmers from learning it. But now many people are turning towards it due to many reasons, primarily the easiness of writing thread-safe(concurrent) code in functional languages. With that in mind, I have tried to cover some key ideas in this post, and have listed some resources at the last. Hoping it will help you! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason for using functional is to help you write modular and compositional code as modular design is the key to successful programming. (From Hughes paper "Why functional programming matters"). Also try to relate it to how coding jobs require people who write such code.
* [https://www.schoolofhaskell.com/](https://www.schoolofhaskell.com/) | ||
* [book.realworldhaskell.org/read/](book.realworldhaskell.org/read/) | ||
|
||
### Scala |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this blog too: Neophytes Guide to Scala
One can easily verify that no state is being changed in the second example. It also looks familiar(something like recursion), isn't it? In FP, most of the functions are indeed implemented through recursion. | ||
|
||
### Getting Started | ||
I would recommend you to first go through ~~scala~~ hashkell tutorials as they are better than scala in getting you started with functional programming. But after all, choice is yours. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: haskell not hashkell
} | ||
} | ||
``` | ||
One can easily verify that no state is being changed in the second example. It also looks familiar(something like recursion), isn't it? In FP, most of the functions are indeed implemented through recursion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In pure functional there is no loop. So, all functions are implemented with pattern matching and recursion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also nothing about pattern matching 😢 ?
```scala | ||
def fib2(n: Int): Int = { | ||
n match { | ||
case 0 => 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use:
case 0 | 1 => n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a tail recursion example as this will overflow for large n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I didn't want it to be a long post with any tutorial, only bare introduction. That's why I have not included pattern matching,tail end, currying, etc. But including it won't hurt though. But, will including pattern matching and tail end suffice? Or should include more topics? Thanks anyway for review.. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least add that stuff. If you want you can also show some examples on lazy evaluation. Since, you are writing it in scala show the effects of declaring a variable as lazy
. Along with that you can also show how sometimes laziness needs to be taken care while IO.
### Getting Started | ||
I would recommend you to first go through ~~scala~~ hashkell tutorials as they are better than scala in getting you started with functional programming. But after all, choice is yours. | ||
|
||
### Hashkell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo again. For some who wants to have a better understanding: Deep insight into functional programming
You should at least mention something about higher order function which is
one of the essential difference between imperative and functional
programming. It provides the 'glue' for composing programs from small
functions.
…On Aug 16, 2017 20:49, "Parv Mor" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In _posts/2017-08-15-Functional_programming.md
<#85 (comment)>:
> +* *Lazy evaluation*: This is one of the wonderful features of FP. It enables us to hold an expression unevaluated unless there is an actual need of using it. It avoids repeated evaluation of same expressions.
+
+So, In FP, programs are executed by just evaluating expressions(without changing state), not by executing statements(which change global state). For example,
+Fibonacci sequence(using imperative style):
+```python
+def fib1(n, first=0, second=1):
+ while n != 0:
+ n = n - 1
+ first = second
+ second = first + second
+```
+Using functional style(in scala):
+```scala
+def fib2(n: Int): Int = {
+ n match {
+ case 0 => 0
At least add that stuff. If you want you can also show some examples on
lazy evaluation. Since, you are writing it in scala show the effects of
declaring a variable as lazy. Along with that you can also show how
sometimes laziness needs to be taken care while IO.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#85 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABrck18UDWM1syu5ZnwQ-GIihSJEDz0Yks5sYwhrgaJpZM4O33Ni>
.
|
b5ffe87
to
3c3a7a7
Compare
No description provided.