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

  • Home
  • SEARCH
  • 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 899159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:10:19+00:00 2026-05-15T15:10:19+00:00

I am a C# developer. Coming from OO side of the world, I start

  • 0

I am a C# developer. Coming from OO side of the world, I start with thinking in terms of interfaces, classes and type hierarchies. Because of lack of OO in Haskell, sometimes I find myself stuck and I cannot think of a way to model certain problems with Haskell.

How to model, in Haskell, real world situations involving class hierarchies such as the one shown here: http://www.braindelay.com/danielbray/endangered-object-oriented-programming/isHierarchy-4.gif

  • 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-15T15:10:19+00:00Added an answer on May 15, 2026 at 3:10 pm

    Let’s assume the following operations: Humans can speak, Dogs can bark, and all members of a species can mate with members of the same species if they have opposite gender. I would define this in haskell like this:

    data Gender = Male | Female deriving Eq
    
    class Species s where
        gender :: s -> Gender
    
    -- Returns true if s1 and s2 can conceive offspring
    matable :: Species a => a -> a -> Bool
    matable s1 s2 = gender s1 /= gender s2
    
    data Human = Man | Woman
    data Canine = Dog | Bitch
    
    instance Species Human where
        gender Man = Male
        gender Woman = Female
    
    instance Species Canine where
        gender Dog = Male
        gender Bitch = Female
    
    bark Dog = "woof"
    bark Bitch = "wow"
    
    speak Man s = "The man says " ++ s
    speak Woman s = "The woman says " ++ s
    

    Now the operation matable has type Species s => s -> s -> Bool, bark has type Canine -> String and speak has type Human -> String -> String.

    I don’t know whether this helps, but given the rather abstract nature of the question, that’s the best I could come up with.

    Edit: In response to Daniel’s comment:

    A simple hierarchy for collections could look like this (ignoring already existing classes like Foldable and Functor):

    class Foldable f where
        fold :: (a -> b -> a) -> a -> f b -> a
    
    class Foldable m => Collection m where
        cmap :: (a -> b) -> m a -> m b
        cfilter :: (a -> Bool) -> m a -> m a
    
    class Indexable i where
        atIndex :: i a -> Int -> a
    
    instance Foldable [] where
        fold = foldl
    
    instance Collection [] where
        cmap = map
        cfilter = filter
    
    instance Indexable [] where
        atIndex = (!!)
    
    sumOfEvenElements :: (Integral a, Collection c) => c a -> a
    sumOfEvenElements c = fold (+) 0 (cfilter even c)
    

    Now sumOfEvenElements takes any kind of collection of integrals and returns the sum of all even elements of that collection.

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

Sidebar

Related Questions

As a developer coming from a Windows background, I'd always find the different Powertoys
From a web developer point of view, what changes are expected in the development
From a desktop application developer point of view, is there any difference between developing
Coming from C++ & MFC background, is there any better (maintainability/customization) platform in developing
During hiring a .NET web developer I give the candidate a coding test. I
http://developer.yahoo.com/javascript/howto-proxy.html Are there disadvantages to this technique? The advantage is obvious, that you can
Having been a PHP developer on LAMP servers for quite a while, is there
I'm a PHP developer, and I use the MVC pattern and object-oriented code. I
I am a web-developer working in PHP. I have some limited experience with using
The .NET coding standards PDF from SubMain that have started showing up in the

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.