3

I'm writing a console application that needs to prompt the user for several things. I'm using the turtle library.

My function looks like this:

askInput :: IO (Maybe Text)
askInput = do
    echo "Input something: "
    s <- readline
    return s

But echo is implemented using putStrLn and as a result, will print its argument with a trailing newline.

Is there an input function in the turtle library similar to Python's raw_input, that combines prompting followed by reading the user input?

Mariano
  • 1,357
  • 3
  • 17
  • 30

2 Answers2

5

You can import from the text package and use many functions which aren't exported from turtle. In this case:

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Text.IO as Text

main = Text.putStr "Input something: " -- doesn't print newline
András Kovács
  • 29,931
  • 3
  • 53
  • 99
2

I also want to mention that turtle has a newly added printf function which outputs a formatted string without the trailing newline, so another solution is:

{-# LANGUAGE OverloadedStrings #-}

import Turtle

main = printf "Input something: "
Gabriella Gonzalez
  • 34,863
  • 3
  • 77
  • 135