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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:48:55+00:00 2026-05-22T01:48:55+00:00

Working through tutorials etc. in ghci – so far so good. I’m so completely

  • 0

Working through tutorials etc. in ghci – so far so good. I’m so completely missing something though : my function builds an IO [FilePath] “thing”. In ghci it comes out like this:

["xml","velocity.log.1","velocity.log"] (list truncated for brevity)

I see that the function is doing what I want. Next step is I want to “print” that out myself.

Nothing I do lets me print the result. I don’t want to perpetuate my Java/C#/Python habits in Haskell – no point in that. I believe there’s a good reason for Haskell doing things differently, but I can’t see how to get the (limited) value out of this function.

module Main (
    main
) where

import RecursiveContents

main = do putStrLn "this"
          getRecursiveContents "/home/xyz/myDir"

This works. But what if I want main to print the result of getRecursiveContents "/home/xyz/myDir" ?

In ghci I can just type/paste getRecursiveContents "/home/xyz/myDir" and the stuff spews out – what do I have to do to print it myself?

If I do :

let xyz = getRecursiveContents "/home/xyz/myDir" in ghci, the only thing I can do with xyz is type:
xyz <enter> and see the result.

I cannot do head, tail, etc. etc.. I know that IO [FilePath] is something special and not a the same as array or list [a] – but nothing I do is helping me to understand getting past this.

I must be missing something – something I can’t find in Learn You a Haskell, or Real World Haskell. Am I not rtfm-ing in the right place?

Any feedback or dope-slaps appreciated.

  • 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-22T01:48:57+00:00Added an answer on May 22, 2026 at 1:48 am

    To get the results of an IO action (i.e. to run the action) you bind the results of the IO computation to a variable:

    Assuming:

    getRecursiveContents :: FilePath -> IO String
    

    Then you can just print the result:

    main = do str <- getRecursiveContents "/home/xyz/myDir"
              print str
    

    Obviously this is just an example, but when the function really is just two lines people don’t usually use do notation and avoid explicitly naming the intermediate variable of str:

    main = getRecursiveContents "/home/xyz/myDir" >>= print
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just got done working through the Django tutorials for the second time, and
I'm new to Ruby and working through some tutorials/screencasts. I've reached the section where
Am stumbled - went through docs, tutorials, etc, and am not sure what I
I'm working through a tutorial on using OpenSSL and when I try something rather
i am just starting with RoR and working through some tutorials, there is however
Working through the summer of nHibernate tutorials have gotten to the section on queries.
I'm working through some Prolog tutorials (nothing better to do and I found out
I am working my way through the tutorials at Android Developers , and have
I'm working through the Java Ranch Cattle Drive online tutorials and got up to
I am working through some tutorials for git and don't understand the difference between

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.