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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:36:48+00:00 2026-06-17T11:36:48+00:00

For this piece of haskell code: isIn :: (Eq a) => [a] -> [a]

  • 0

For this piece of haskell code:

isIn :: (Eq a) => [a] -> [a] -> Bool
needle `isIn` haystack = any (needle `isPrefixOf`) (tails haystack)

This is a function definition I believe. How do I understand what the input arguments are and what the return type is?

For example: what is (Eq a)?

  • 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-17T11:36:49+00:00Added an answer on June 17, 2026 at 11:36 am

    Eq is what’s called a typeclass. It declares a few functions, in this case == and friends, and we can make instances of that typeclass which provide definitions for == and others.

    This means that when we have something that’s an instance of the Eq typeclass, we know we can use == on it.

    The trick here is that in our function, we need to have types which make it possible to check that they’re equal. If we just had [a] -> [a] -> Bool then we’d be in trouble because we’d have just promised that our implementation works on things without an == operator which it doesn’t.

    Because of this we use the => which adds context to our function definition. It says something like “This will work for any a as long as a is an instance of the Eq typeclass”. That way, we can use == safely and know that all our argument types will implement it appropriately.

    Quick Illustration

    This is an error:

    doIfEqual :: a -> a -> (a -> a -> [a])
    doIfEqual a b f = if a==b then f a b else []
    

    but this works because we specify a is an instance of Eq

    doIfEqual (Eq a) => a -> a -> (a -> a -> [a])
    doIfEqual a b f = if a==b then f a b else []
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've come across a piece of Haskell code that looks like this: ps@(p:pt) What
I have found this piece of code in the Haskell sendfile package: http://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Network/Socket/SendFile/Linux.hsc --
Consider this piece of code var crazy = function() { console.log(this); console.log(this.isCrazy); // wrong.
I have piece of code like this in my Haskell program: ... start <-
this piece of code is not something unknown to JS developers function get_counter() {
I'm going through a Haskell tutorial and am given this piece of code to
This piece of code works in Firefox and IE: $('input').click(function() { $(group).animate({ 'width' :
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
This piece of code is from Adobe docs : package { import flash.display.Loader; import
This piece of code is supposed to go through a list and preform some

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.