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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:59:24+00:00 2026-05-30T03:59:24+00:00

I’m learning Haskell, and these are my first steps in trying to understand the

  • 0

I’m learning Haskell, and these are my first steps in trying to understand the syntax. I’m having a very hard time, and the language reference is not helpful, unfortunately.

I tried to do :type (line_length 1 2 3 4) and I have red the reference on printf However, it uses symbols with vague meaning instead of words. So, I’m stuck and asking for help.

Put simple: what do I write in place of ???.

line_length :: Integer -> Integer -> Integer -> Integer -> ???
line_length ax ay bx by =
            printf ("The length of the line between the points" ++
            "(%d,%d) and (%d,%d) is %.5f\n") ax ay bx by
            ((((fromIntegral (ax - bx)) ** 2.0) +
            ((fromIntegral (ay - by))) ** 2.0) ** 0.5)
  • 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-30T03:59:26+00:00Added an answer on May 30, 2026 at 3:59 am

    The overloaded return type of printf :: PrintfType r => String -> r can be a little confusing, but it helps to look at the PrintfType instances which are available:

    1. First, we have this instance:

      instance (PrintfArg a, PrintfType r) => PrintfType (a -> r)
      

      This one is used to allow printf to take a variable number of arguments. This makes sense due to currying, but you probably won’t think of it as the “true” return type of the function. For more information about how this works, see How does printf work in Haskell?.

    2. Then we have this instance,

      instance PrintfType (IO a)
      

      This means that we can use it as an IO action. Similar to print, this will print the result to standard output. The result of the action is undefined, so you should just ignore it.1

      > printf "Foo %d\n" 42 :: IO ()
      Foo 42
      > it
      *** Exception: Prelude.undefined
      
    3. And finally,

      instance IsChar c => PrintfType [c]
      

      The type class here is mostly to allow this to be Haskell 98 compliant. Since the only instance of IsChar is Char, you can think of this as

      instance PrintfType String
      

      but that would require the GHC-specific extension FlexibleInstances.

      What this instance means is that you can also just return a String without printing it, similar to sprintf in C.

      > printf "Foo %d\n" 42 :: String
      "Foo 42\n"
      

    So depending on whether you want to print the result or just return it, you can replace ??? with either IO () or String in your example.

    However, there is another problem with your code in that the compiler is unable to determine which type you wanted the last argument to be, so you have to help it out with a type annotation:

    line_length :: Integer -> Integer -> Integer -> Integer -> String
    line_length ax ay bx by =
                printf ("The length of the line between the points" ++
                "(%d,%d) and (%d,%d) is %.5f\n") ax ay bx by
                ((((fromIntegral (ax - bx)) ** 2.0) +
                ((fromIntegral (ay - by))) ** 2.0) ** 0.5 :: Double)
    

    1 This is done to avoid extensions. With extensions, we could write instance PrintfType (IO ()) and the result would be ().

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm trying to create an if statement in PHP that prevents a single post

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.