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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:05:05+00:00 2026-05-31T20:05:05+00:00

I am currently working on Problem 62 I have tried the following code to

  • 0

I am currently working on Problem 62

I have tried the following code to solve it:

data Tree a = Empty | Branch a (Tree a) (Tree a)
              deriving (Show, Eq)

internals :: Tree a -> [a]

internals (Branch a Empty Empty) = []

internals (Branch a b c) = [a]++(internals b)++(internals c)

internals (Branch a b Empty) = [a]++(internals b)

internals (Branch a Empty c) = [a]++(internals c)

Which basically says:

  1. If both the children are empty don’t include that list element in the list of internals.
  2. If both children are non-empty, that node (a) is an internal include it, and keep checking to see any of a‘s children are also internal.
  3. If one of the children is non-empty, that node is internal, and recursively keep checking if the child is also an internal node.

In GHCi I have ran the following:

> let tree4 = Branch 1 (Branch 2 Empty (Branch 4 Empty Empty)) (Branch 2 Empty Empty)
> internals tree4

and get the following runtime error:

[1,2*** Exception: Untitled.hs:(6,1)-(12,49): Non-exhaustive patterns in function internals

I don’t understand why this thing is non-exhaustive, I thought it would go to branch 1, notice it’s children are non-empty, then go down both branch 2s and find out one branch is empty, one is not, stop at the one that is, and keep going down the one that isn’t, until branch “4”, and end it there. It sort of does, I do get 1, 2 in the list, but why is it not exhaustive?

Thanks in advanced.

Thank you for the help Tikhon changed my function to this:

data Tree a = Empty | Branch a (Tree a) (Tree a)
              deriving (Show, Eq)

internals :: Tree a -> [a]

internals (Branch a Empty Empty) = []

internals (Branch a b Empty) = [a]++(internals b)

internals (Branch a Empty c) = [a]++(internals c)

internals (Branch a b c) = [a]++(internals b)++(internals c)
  • 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-31T20:05:06+00:00Added an answer on May 31, 2026 at 8:05 pm

    The order of patterns matters. Since Branch a b c matches everything that isn’t just Empty, including something like Branch a b Empty, your third and fourth cases never get hit.

    This should fix it:

    internals :: Tree a -> [a]
    internals (Branch a Empty Empty) = []
    internals (Branch a b Empty)     = [a] ++ internals b
    internals (Branch a Empty c)     = [a] ++ internals c
    internals (Branch a b c)         = [a] ++ internals b ++ internals c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem using subversion: I'm currently working on the trunk of
I`m currently working on a script, and I have the following situation. function somnicefunction()
I have been working with the slider and am using the following code: $(function(){
I have a problem with a SQL query. I got the following query working,
I am currently working on a programming related problem where I am attempted to
I'm having a strange problem with php PDO and mysql. I have the following
I got the following problem: I have an object called tempScore for my game.
I'm working with the following code that is contained in a .ASPX.CS page... img
I have the following code. PHP side: <?php print_r($_POST); print_r($_GET); die(); ?> In JavaScript:
I have this project I'm working on. The following conditions apply In this project

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.