Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:50:07+00:00 2026-05-26T16:50:07+00:00

Coming from the OOP I started in the last weeks to read about functional

  • 0

Coming from the OOP I started in the last weeks to read about functional programming and started to learn Haskell. Very often I was reading that (pure) functions are easier to test since there are no complicated set-up and tear-down routines. This sounds reasonable and I was agreeing. Composing these functions allows me to build more complicated functions with a very well tested “base”.

As I stared to write my first programs some functions got more and more parameters and so I started to create new data types which are for me similar to structures. Of course the data types bundle what logically belongs together and are sometimes composed of other data types.

Calling functions then like

MyTpye = foo(MyTpye, someParam)

feels a little bit like doing OOP with really ugly syntax as back in the times of C with function pointers in structs:

MyType = foo(this, someParam) = {
   ... 
   return modified_copy_of_this; 
}

Testing these functions also requires me to setup the my new data type first which can be complicated and I just feel that I don’t win much.

I suppose I am still too narrow minded and focused on the OOP way of writing code. I just have the feeling that calling functions on data types is nothing else than calling methods on immutable objects (of course each setter would have to return a modified version of the object).

Can somebody please clarify this a little bit for me?

Thank you very much!

I added this Haskell example. These are my first steps and I tried to avaoid posting ugly code like this.
It’s just the first parts of a reinformcement learning algorithm. Setting up an “environment” with available states, actions and a reward function.

type Action = [Double]
type State  = [Double]

data StateSet = StateSet [State] deriving (Show)
data ActionSet = ActionSet [Action] deriving (Show)

data Environment = Environment {
    availableStates :: StateSet,
    availableActions:: ActionSet,
    currentState    :: State,
    rewardfnc       :: State -> Action -> Double,
    lastReward      :: Double
} 

rewardFunction :: State -> Action -> Double
rewardFunction s a = (-1)

doAction :: Environment -> Action -> Environment
doAction env a = Environment (availableStates env) (availableActions env) a (rewardfnc env) ((rewardfnc env) (currentState env) a)

getReward :: Environment -> Double
getReward env = (lastReward env)    

states = StateSet [[i,j] | i <- [1..10], j <- [1..10]]
actions = ActionSet [[i,j] | i <- [1..10], j <- [1..10]]

initEnv = Environment states actions [0,0] rewardFunction 0.0
env = doAction initEnv [2,2]
reward = getReward(env)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:50:08+00:00Added an answer on May 26, 2026 at 4:50 pm

    I felt the same way as you did when I first started learning functional programming — that calling functions on data types is nothing else than calling methods on immutable objects.

    I think it’s important to realize that this is one way to look at FP, and not the only way. Simiarly, the OOP methodology of grouping data and procedures together into classes is one way to think about programming, but not the only way. For some problems, OOP leads to great solutions, while for others, it’s not so good.

    The example you’ve given, or the way you’ve chosen to solve it, may just happen to a better fit for OOP than for FP. Not that you can’t solve it with FP, just that doing so seems a little awkward and forced — as you’ve noticed. My guess as to the reason that this example is giving you trouble, is because it deals with changing an environment — very natural for OOP.

    There are other problems for which the FP solution will seem natural and simple, and the OOP version awkward and forced. Think of problems where the solution involves transforming the input into output:

    • input: a set of maps (i.e. a database table) output: a report, grouped on one of the columns, filtered on a predicate, with aggregate functions applied to the columns
    • input: a program text output: a parse tree
    • input: a parse tree output: statistics on function length, variable names, number of comments, etc.

    To sum it up, if you continue with functional programming, you’ll find that there are other problems for which FP is well-suited, and whose solutions are much simpler and natural than they would be in OO languages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

coming from the Ocaml community, I'm trying to learn a bit of Haskell. The
I am coming from a PHP background and I am familiar with OOP concepts,
Coming from C++, I find generic programming indispensable. I wonder how people approach that
Coming from Java , I'm used to the package structure (com.domain.appname.tier) Now I've started
I am close to completion of my first OOP project, coming from a C
Coming from Java programming, I'm used to the general Main<->Test Maven-setup for a project.
Coming from a c++ background I'm curious about object assignment in Ruby. What considerations
Coming from a PHP background, I'm trying to learn C++, since I find it
Coming from Haskell, I'd like to know if there is a way to avoid
Coming from a corporate IT environment, the standard was always creating a class library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.