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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:03:03+00:00 2026-06-12T08:03:03+00:00

I’m trying to learn Haskell, thinking that it would be the perfect language to

  • 0

I’m trying to learn Haskell, thinking that it would be the perfect language to implement Combinatorial Game Theory. I’ve done this to some extent in Python to teach myself OOP principles and operator overloading, but Haskell attracts me because it seems more mathematical in its syntax, and having a math background I really like that. Also, having lazily implemented infinite lists is pretty amazing.

Anyway, what I have so far is a data structure that compiles but the first function I’ve written using it gives me:

Prelude> :l cgt
[1 of 1] Compiling Main             ( cgt.hs, interpreted )

cgt.hs:8:30:
    Couldn't match expected type `([Game], b0)' with actual type `Game'
    In the first argument of `fst', namely `b'
    In the second argument of `(:)', namely `(fst b)'
    In the expression: a : (fst b)
    Failed, modules loaded: none.

Here is my code…

--A game that is Zero (base case) is two empties
--Anything else must be two lists of games, a left list and a right list.

data Game = Zero
          | Position ([Game], [Game])

putL :: Game -> Game -> Game
putL a b = Position (a :(fst b), snd b)

I realize that a Game is somewhat like a Tree as discussed on the Wikibook , but they have additional restrictions.

  1. A Position (kin to a tree node) can have many possible moves
  2. A Position may only contain other Games
  3. There is a special Game, Zero, that has no possible moves.
  4. All games are built up using Zero.

So when I wrote putL I say, “Take a Game a and another Game b, and cons a into the first part of b, and leave the second part of b alone, returning a Position (which is a kind of Game).” At least, that is what I am trying to do. Instead Haskell is thinking the type I’m returning is ([Game], b0) and I don’t know why.

Thank you! I appreciate your help.

  • 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-12T08:03:04+00:00Added an answer on June 12, 2026 at 8:03 am

    You can’t use the fst and snd functions on something of type Game. Since you haven’t declared names for your fields in your data constructors Zero and Position, the only way to actually access them is via pattern matching. (Note that I also removed the unnecessary tuple in the Position constructor)

    data Game
      = Zero
      | Position [Game] [Game]
    
    putL :: Game -> Game -> Game
    putL game Zero = ???
    putL game (Position games1 games2) = Position (game : games1) games2
    

    Now, I obviously don’t know what you want to happen for the Zero constructor, so you’ll have to fill in those ???‘s yourself.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I know there's a lot of other questions out there that deal with this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.