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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:32:00+00:00 2026-05-15T05:32:00+00:00

I have an haskell problem. putStrLn is supposed to take a [Char], or a

  • 0

I have an haskell problem. putStrLn is supposed to take a [Char], or a String, and even though it seems like I give that to mr Compiler, he still complains.

*** Expression     : putStrLn line
*** Term           : line
*** Type           : Char
*** Does not match : [Char]

The code that it refers to is this:

getV::[[(Char,Float)]] -> IO ()
getV [] = putStrLn ""
getV (x:xs) = do line <- getS x
   putStrLn line      <-- Complaining line
   getV xs

getS::[(Char,Float)] -> String
getS [] = ""
getS ((c,f):str) = do a <- "(L" ++ [c] ++")" ++ getS str
    return a

I did strip it a little bit, but it should be exactly the same behaviour. getS do return a String and that string is the argument for putStrLn. So what is the problem? :/

  • 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-15T05:32:01+00:00Added an answer on May 15, 2026 at 5:32 am

    Since your getS returns a String, not an IO String, there’s no need to “extract” the pure value with <-.

    Just use

    do
      let line = getS x
      putStrLn line
      getV xs
    

    Also, there’s a mapM function which you can

    getV xs = mapM (putStrLn.getS) xs
    

    and your getS is using monads unnecessarily.

    getS [] = ""
    getS ((c,_):str) = "(L" ++ [c] ++ ")" ++ getS str
    

    Of course, it’s possible to write it using built-in functions only.

    getS ps = concatMap (\(c,_) -> "(L" ++ [c] ++ ")") ps
    

    The reason your code doesn’t fail on the line <- getS x line, and line becomes a Char is because List is also a monad. For instance, we can write the Cartesian product as

    cartesian :: [a] -> [b] -> [(a,b)]
    cartesian xs ys = do
        x <- xs    -- # Now x is of type 'a', representing any element in xs
        y <- ys    -- # Now y is of type 'b', representing any element in ys
        return (x, y) -- # Return the tuple composed of any elements in xs and ys.
    

    In fact, list comprehension is based on this monadic property of list.

    cartesian xs ys = [(x, y) | x <- xs, y <- ys]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.