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 674445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:42:27+00:00 2026-05-14T00:42:27+00:00

I have this code that I want to make point-free; (\k t -> chr

  • 0

I have this code that I want to make point-free;

(\k t -> chr $ a + flip mod 26 (ord k + ord t -2*a))

How do I do that?

Also are there some general rules for point free style other than “think about this amd come up with something”?

  • 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-14T00:42:28+00:00Added an answer on May 14, 2026 at 12:42 am

    To turn a function

    func x y z = (some expression in x, y and z)
    

    into point-free form, I generally try to follow what is done to the last parameter z and write the function as

    func x y z = (some function pipeline built using x and y) z
    

    Then I can cancel out the zs to get

    func x y = (some function pipeline built using x and y)
    

    Then repeating the process for y and x should end up with func in point-free form. An essential transformation to recognise in this process is:

        f z = foo $ bar z    -- or f z = foo (bar z)
    <=> f z = foo . bar $ z
    <=> f   = foo . bar
    

    It’s also important to remember that with partial evaluation, you can “break off” the last argument to a function:

    foo $ bar x y == foo . bar x $ y    -- foo applied to ((bar x) applied to y)
    

    For your particular function, consider the flow that k and t go through:

    1. Apply ord to each of them
    2. Add the results
    3. Subtract 2*a
    4. Take the result mod 26
    5. Add a
    6. Apply chr

    So as a first attempt at simplifying, we get:

    func k t = chr . (+a) . (`mod` 26) . subtract (2*a) $ ord k + ord t
    

    Note that you can avoid flip by using a section on mod, and sections using - get messy in Haskell so there’s a subtract function (they clash with the syntax for writing negative numbers: (-2) means negative 2, and isn’t the same as subtract 2).

    In this function, ord k + ord t is an excellent candidate for using Data.Function.on (link). This useful combinator lets us replace ord k + ord t with a function applied to k and t:

    func k t = chr . (+a) . (`mod` 26) . subtract (2*a) $ ((+) `on` ord) k t
    

    We’re now very close to having

    func k t = (function pipeline) k t
    

    and hence

    func = (function pipeline)
    

    Unfortunately Haskell is a bit messy when it comes to composing a binary function with a sequence of unary functions, but there is a trick (I’ll see if I can find a good reference for it), and we end up with:

    import Data.Function (on)
    
    func = ((chr . (+a) . (`mod` 26) . subtract (2*a)) .) . ((+) `on` ord)
    

    which is almost a nice neat point-free function pipeline, except for that ugly composing trick. By defining the .: operator suggested in the comments on this page, this tidies up a little to:

    import Data.Function (on)
    
    (.:) = (.).(.)
    
    func = (chr . (+a) . (`mod` 26) . subtract (2*a)) .: ((+) `on` ord)
    

    To polish this some more, you could add some helper functions to separate the letter <-> Int conversion from the Caesar cipher arithmetic. For example: letterToInt = subtract a . ord

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

Sidebar

Related Questions

I have this html code that i want to edit with jQuery. Here is
I have this code in jQuery, that I want to reimplement with the prototype
I have code that I want to look like this: List<Type> Os; ... foreach
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that performs an ajax call and loads the results into
I have this code that works in a unit test but doesn't work when
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
I have this code and I want to keep it elegant. I got stuck

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.