Re: [ljc] How to think as "functional language programer"

From: Kevin W.
Sent on: Wednesday, October 2, 2013 2:25 PM
Both viewpoints are correct.

There's definitely some concept of evolving "state" within the program as a whole, but you never mutate state within a named variable.

Taken to the extreme in a language like Haskell, you end up working with "State Monads" and "IO Monads" where you pass around a value to every function that has any form of side effect (such as printing to the console).  The function then clones this state and returns an updated version.  This global state often contains nothing more than a monotonically incrementing integer.

In this way, you can preserve the idea of pure functions even across operations such as printing log output and writing to files.

Scala programs rarely take things to this extreme, but if you really want to maintain functional purity like this then scalaz is the way to go.  Unlike Haskell, neither scalac nor the JVM is designed to optimise this style of program, so you'll take a small performance hit. On the other hand, there are advantages in terms of composability and the ease of reasoning about your code.



On 2 October[masked]:02, Martijn Verburg <[address removed]> wrote:
Hi Michael,

It's not nitpicking - it's a valid correction, so thanks! :-), one of my (many) faults is that I never quite explain FP properly :-|

Cheers,
Martijn


On 2 October[masked]:58, Michael Klishin <[address removed]> wrote:
On oct 2, 2013, at 2:43 p.m., Martijn Verburg <[address removed]> wrote:

> This mimics one common aspect of pure FP in that you never change state, e.g. 2 + 4 = 6 - When you add 2 to 4, you're not changing the value of either 2 or 4, you're applying a function (of sorts) and creating a new value 6.

Martijn,

Sorry to nitpick but FP is not about "not changing state". It's about changing
state in a *predictable manner*, and one way to do that is by not modifying values but
produce new ones instead.

MK





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
http://www.meetup.com/Londonjavacommunity/
This message was sent by Michael Klishin ([address removed]) from LJC - London Java Community.
To learn more about Michael Klishin, visit his/her member profile: http://www.meetup.com/Londonjavacommunity/members/111495012/

Set my mailing list to email me

As they are sent
Don't send me mailing list messages
http://www.meetup.com/Londonjavacommunity/list_prefs/?pref=0

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]






--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Martijn Verburg ([address removed]) from LJC - London Java Community.
To learn more about Martijn Verburg, visit his/her member profile
To report abuse or block this person, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]



--
Kevin Wright
mail: [address removed]
gtalk / msn : [address removed]
vibe / skype: kev.lee.wright
steam: kev_lee_wright

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference, in collaboration with the LJC 12/13 Jun 14

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • New Relic

    New Relic makes sense of billions of metrics a day in real time.

  • Hazelcast

    Hazelcast is the leader in operating in-memory computing.

  • Packt Publishing

    A publishing company specializing on specific technologies and solutions

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy