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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:19:31+00:00 2026-05-12T18:19:31+00:00

I wrote a Haskell function that calculates the factorial of every number in a

  • 0

I wrote a Haskell function that calculates the factorial of every number in a given list and prints it to the screen.

factPrint list =
if null list
    then putStrLn ""
    else do putStrLn ((show.fact.head) list)
        factPrint (tail list)

The function works, but I find the third line a bit confusing.
Why hasn’t the compiler(GHC) reported an error on it since there is no “do” before the “putStrLn” (quasi?)function?
If I omit “do” from the 4th line, an error pops up as expected.

I’m quite new to Haskell and its ways, so please pardon me if I said something overly silly.

  • 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-12T18:19:31+00:00Added an answer on May 12, 2026 at 6:19 pm
    do putStrLn ((show.fact.head) list)
       factPrint (tail list)
    

    is actually another way of writing

    putStrLn ((show.fact.head) list) >> factPrint (tail list)
    

    which, in turn, means

    putStrLn ((show.fact.head) list) >>= \_ -> factPrint (tail list)
    

    The do notation is a convenient way of stringing these monads together, without this other ugly syntax.

    If you only have one statement inside the do, then you are not stringing anything together, and the do is redundant.

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

Sidebar

Related Questions

I'm trying to write a Haskell function that checks if a list of integers
I wrote the following function in haskell, as it will enumerate every integer: integers
I wrote a function in haskell that takes a few parameters like Word32, String
i'm new in Haskell. I have to write function that takes list of Integers
I am trying to write haskell function that takes list of lists and find
I'm trying to write a function in haskell that reverses lists recursively. I wrote
As an exercise I wrote a short Haskell function that returns the first four
I am looking into making a text based game that I wrote in Haskell
Possible Duplicate: Write a function that returns the longest palindrome in a given string
I am teaching myself Haskell. I want to write a function that recursively finds

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.