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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:16:21+00:00 2026-05-27T23:16:21+00:00

Quick question, what is wrong with this? (get) :: [a] -> Int -> a

  • 0

Quick question, what is wrong with this?

(get) :: [a] -> Int -> a   -- <- line 21
(x:xs) get 0 = x
(x:xs) get (n+1) = xs get n

ghci gives this error when I try to load the file that contains that code.

Prelude> :load ch6.hs 
[1 of 1] Compiling Main             ( ch6.hs, interpreted )

ch6.hs:21:0: Invalid type signature
Failed, modules loaded: none.

I’m trying to make get an infix operator.

  • 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-27T23:16:23+00:00Added an answer on May 27, 2026 at 11:16 pm

    You shouldn’t have parentheses around get, to start with. The syntax for the whole definition looks a bit off, though. I’m guessing you wanted something like this:

    get :: [a] -> Int -> a
    get (x:xs) 0 = x
    get (x:xs) (n+1) = xs `get` n
    

    Note the backticks around get in order to use it infix, which is necessary here because the rules for an alphanumeric identifier are different from operators: Operators are made of symbols, are are infix by default, and to write them without arguments or use them prefix, you put them in parentheses. Alphanumeric identifiers are prefix by default, and surrounding them with backticks lets you use them infix.

    You can use the backticks on the left-hand side as well, if you want, but that looks a bit odd to my eye:

    (x:xs) `get` 0 = x
    (x:xs) `get` (n+1) = xs `get` n
    

    Incidentally, the pattern syntax n+1 is deprecated, so you probably shouldn’t use that. Instead, do this:

    (x:xs) `get` n = xs `get` (n - 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question, What have I done wrong here. The purpose of this code is
Quick question; I replaced a .css file which I was referencing in html/php that
Just a quick question, can someone tell me where this is going wrong, I'm
Quick question. What do you think, I have a few sites that use a
Quick question. There is a legacy website (that is not under my control and
I have a quick question about the following expression: int a_variable = 0; if(0!=a_variable)
The quick question: is there a pure PHP library that can extract a frame
Just a quick question that no doubt someone out there will know the answer
I was wondering if anyone could answer me this quick question. I tried searching
Hopefully this question is quick and painless I have a mvc view where i

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.