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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:45:34+00:00 2026-06-06T01:45:34+00:00

Haskell is beautiful. That’s a fact. It’s concise, fast etc. Many of you will

  • 0

Haskell is beautiful. That’s a fact. It’s concise, fast etc. Many of you will admit that writing in it is a great pleasure. On the other hand I think that its conciseness might be a disadvantage when people try to write too sophisticated code. For example I recently opened my friend’s project and found something like this:

stationDepartures id sc=map (\(s1,list)->(stationName $ (stationMap $ system sc) Map.! s1,list)) ( Map.toList (Map.fromListWith (++) (map (\((s1,s2),(d,start,dur))->(s2,[start])) (Map.toList (Map.filterWithKey (\(s1,s2) _ ->s1==id) (Map.unions (List.map times (Map.elems $ schedule sc))))))))

This one-liner was absolutely unreadable to me. This is of course a quite extreme example but it helped me to realize that maybe my Haskell code might seem unreadable to others. I started to wonder what are the principles of creating a beautiful code in Haskell. I found that e.g. lambda functions are considered by some people as superfluous because they make the code less readable. What do you think about that? What requirements should Haskell code meet to be considered as “beautiful”?

  • 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-06-06T01:45:39+00:00Added an answer on June 6, 2026 at 1:45 am

    I’m going to assume that you asked, “How can I write this one-liner in a more readable fashion?” Otherwise, the question is a bit too subjective.

    One-liners are problematic in any language, although Haskell can be especially problematic due to the abundance of binary operators (with precedence rules), higher order functions (which are difficult to name), and (gasp!) higher-order functions which are binary operators. However, we can start by noticing that most of the parentheses can be eliminated in the one-liner, and we can show that the expression is a series of functions composed together. Each function can be written on a separate line and composed with ., with a final $ to apply the whole thing to an argument.

    stationDepartures id sc =
      map (\(s1,list) -> (stationName $ (stationMap $ system sc) Map.! s1,
                          list)) .
      Map.toList .
      Map.fromListWith (++) .
      map (\((s1,s2),(d,start,dur)) -> (s2,[start])) .
      Map.toList .
      Map.filterWithKey (\(s1,s2) _ -> s1 == id) .
      Map.unions .
      List.map times .
      Map.elems $ schedule sc
    

    To me, this is fairly readable because I recognize patterns in there, and I can follow the flow of data from bottom to top. (Note: this is why all of the Map functions take a Map as the last parameter instead of the first parameter. Remember this when you are designing your Haskell APIs!)

    For example, the Map.toList . Map.fromListWith f pattern is very common, it’s just hard to see it in the one-liner (to my eyes, at least). The code isn’t really that sophisticated, it’s just had it’s line breaks surgically removed.

    But, readability is subjective.

    You’ll develop a style that is easy for you to read. As you understand the language more, the style will evolve, and your sense of “beautiful code” will evolve. Just let it happen, and try not to get bogged down too much in rewrites that you don’t have fun any more.

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

Sidebar

Related Questions

Using Haskell, I'm writing a function that counts the total number of leaves in
Haskell 98 specification says that the entry point of a program, namely, function main
In Haskell, how can I generate Fibonacci numbers based on the property that the
In Haskell, lifted type products mean that there's a semantic difference between (a,b,c) and
The Haskell wiki states that you should use Cabal as your build system. However,
The Haskell wiki shows that you need to both set a compilation flag and
In Haskell, is there a way to compare that all wildcards are of the
I like haskell and many things connected with it as its type-engine, lot of
since Haskell has such expressive type system, is there something supported directly that we
my Haskell* is a bit rusty, so i can imagine that I’m missing the

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.