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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:56:45+00:00 2026-06-18T17:56:45+00:00

I have a funciton which compiles successfully in haskell. It looks like this: suffix

  • 0

I have a funciton which compiles successfully in haskell.

It looks like this:

suffix :: Int -> String
suffix i 
   | i==0                 = "th"
   | i==1                 = "st"
   | i==2                 = "nd"
   | i==3                 = "rd"
   | i>=4 || i<=9         = "th"
   | i<0                  = error "Must be positive integer"     ----------NOT WORKING?
   | otherwise            = suffix(i `rem` 10)      

It does not work that I can tell at least with the error line for the i<0 guard. When I enter into GHCI and add a “-” to the a number: suffix -5 I get the same error message I would get if I completely left this case off.

I’d like it to display my error message obviously. Hopefully someone can spot my issue. Thanks!

  • 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-06-18T17:56:46+00:00Added an answer on June 18, 2026 at 5:56 pm

    Basic Haskell syntax weirdness. This is the only case like it in the language.

    suffix -5 is suffix - 5 is (-) suffix 5. The - character is treated as an infix binary operator, like all punctuation-named functions in haskell are. That is, unless there are no characters in the expression before the -. The simplest way to do what you want is with suffix (-5). By enclosing it in parens, you are making it syntactically a standalone expression, which means no characters precede the - in the expression.

    This creates its own weirdness, though, in that you can’t create an operator section for subtracting a value from the input. (-5) is not the section that means \x -> x - 5, unlike any other other binary operator in the language. It’s kind of an unfortunate situation that unary negation and binary subtraction use the same symbol, because it means there have to be corner cases like this in Haskell’s syntax.

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

Sidebar

Related Questions

I have a vc++ dll which has a funciton call like this : typedef
I have a function which looks something like this, it returns a noncopyable class
I have code which compiles without error in Visual Studio 2010. But g++ puts
I have a std::atomic which contains a pointer to a member function. Everything compiles
I have a class 'Vector3' which is compiled successfully. It contains both non-friend and
I have the following code which compiles and runs fine under Visual Studio 2008
Right now, I have a ffmeg build script which recognizes libx264 and compiles succesfully.
I have some template code which compiles fine in VC9 (Microsoft Visual C++ 2008)
I have a small application which compiles a source file into executable. The problem
hi i have function which is called by tinker listbox so i cannot return

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.