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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:18:16+00:00 2026-06-05T04:18:16+00:00

I was playing around with typeclasses and made this: class Firstable f where fst

  • 0

I was playing around with typeclasses and made this:

class Firstable f where
  fst :: f a -> a

class Secondable f where
  snd :: f a -> a

I then tried to add an implementation for (,) and realized that I could do:

instance Secondable ((,) a) where
  snd (x,y) = y

I’m pretty sure this works because Secondable should have kind (* -> *) where ((,) a) has that type, however, I don’t know how to implement Firstable for ((,) * a) where * is the bound variable, In my interpretation I am trying to do the equivalent of:

instance Firstable (flip (,) a) where ...

Is there a way to do this in Haskell? Preferably without extensions?

  • 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-05T04:18:18+00:00Added an answer on June 5, 2026 at 4:18 am

    A version with worse parametricity guarantees can be had with MPTCS and Fundeps or with TypeFamilies.

    type family Fst p
    type instance Fst (a,b) = a
    type instance Fst (a,b,c) = a
    

    …

    class First p where
       fst :: p -> Fst p
    
    instance Fst (a,b) where
       fst (a,_) = a
    
    instance Fst (a,b,c) where
       fst (a,_,_) = a
    

    …

    but ultimately, you’ll need to use some extensions.

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

Sidebar

Related Questions

After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
Been playing around with this for a couple of hours and can't seem to
Was playing around a little bit with the TimeSpan class and I started wondering
Playing around with jQuery a bit (sorry, complete noob) I was wondering why this
Im playing around with TryParse() But lets say the parsing fails, then returns false,
Im playing around with the new geometry library made available in boost 1.47 and
Playing around with type-classes I came up with the seemingly innocent class Pair p
While playing around with regexps in Scala I wrote something like this: scala> val
When playing around with git , I sometimes try out things, then abort commands
Am playing around with the standard Wordpress search and am using this code in

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.