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

  • SEARCH
  • Home
  • 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 6201265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:31:18+00:00 2026-05-24T04:31:18+00:00

Consider following function definition in ghci. let myF = sin . cos . sum

  • 0

Consider following function definition in ghci.

let myF = sin . cos . sum 

where, . stands for composition of two function (right associative). This I can call

myF [3.14, 3.14]

and it gives me desired result. Apparently, it passes list [3.14, 3.14] to function ‘sum’ and its ‘result’ is passed to cos and so on and on. However, if I do this in interpreter

let myF y = sin . cos . sum y 

or

let myF y = sin . cos (sum y) 

then I run into troubles. Modifying this into following gives me desired result.

let myF y = sin . cos $ sum y 

or

let myF y = sin . cos . sum $ y 

The type of (.) suggests that there should not be a problem with following form since ‘sum y’ is also a function (isn’t it? After-all everything is a function in Haskell?)

let myF y = sin . cos . sum y -- this should work?

What is more interesting that I can make it work with two (or many) arguments (think of passing list [3.14, 3.14] as two arguments x and y), I have to write the following

let (myF x) y = (sin . cos . (+ x)) y 
myF 3.14 3.14 -- it works! 
let myF = sin . cos . (+) 
myF 3.14 3.14 -- -- Doesn't work!

There is some discussion on HaskellWiki regarding this form which they call ‘PointFree’ form http://www.haskell.org/haskellwiki/Pointfree . By reading this article, I am suspecting that this form is different from composition of two lambda expressions. I am getting confused when I try to draw a line separating both of these styles.

  • 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-24T04:31:19+00:00Added an answer on May 24, 2026 at 4:31 am

    Let’s look at the types. For sin and cos we have:

    cos, sin :: Floating a => a -> a
    

    For sum:

    sum :: Num a => [a] -> a
    

    Now, sum y turns that into a

    sum y :: Num a => a
    

    which is a value, not a function (you could name it a function with no arguments but this is very tricky and you also need to name () -> a functions – there was a discussion somewhere about this but I cannot find the link now – Conal spoke about it).

    Anyway, trying cos . sum y won’t work because . expects both sides to have types a -> b and b -> c (signature is (b -> c) -> (a -> b) -> (a -> c)) and sum y cannot be written in this style. That’s why you need to include parentheses or $.

    As for point-free style, the simples translation recipe is this:

    • take you function and move the last argument of function to the end of the expression separated by a function application. For example, in case of mysum x y = x + y we have y at the end but we cannot remove it right now. Instead, rewriting as mysum x y = (x +) y it works.
    • remove said argument. In our case mysum x = (x +)
    • repeat until you have no more arguments. Here mysum = (+)

    (I chose a simple example, for more convoluted cases you’ll have to use flip and others)

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

Sidebar

Related Questions

The question is to consider the following function definition: def read_value_type(prompt='Enter a Boolean> ',
Howdy. Consider the following: SQL> DECLARE 2 b1 BOOLEAN; 3 b2 BOOLEAN; 4 FUNCTION
Consider the following sequence of events: A view v_Foo is defined A user-defined function
Consider the following function, which does not work in Python, but I will use
Consider the following function that implements non-blocking access to only the one thread. public
Consider the following example: var funcToCall = function() {...}.bind(importantScope); // some time later var
Consider the following piece of code: class foo { private function m() { echo
Consider the following code : HTML: <input type='checkbox' /> <div>Click here</div> JS: $(function() {
Consider the following code enum HorizontalAlignment { Left, Middle, Right }; enum VerticleAlignment {
Consider the following wrapper function that retrys a given function some given number of

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.