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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:26:08+00:00 2026-06-13T08:26:08+00:00

here is my ADT: data Tree a = Val Integer |Tree a |Variable a

  • 0

here is my ADT:

data Tree a = Val Integer
            |Tree a
            |Variable a

I have two questions:

Question 1: use Tree String type to represent some trees?

Question 2: define a function for converting a tree, an element of the datatype Tree String to string: showTree::Tree String -> String

  • 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-13T08:26:09+00:00Added an answer on June 13, 2026 at 8:26 am

    With respect to your second question, coverting a tree into a string, just derive Show and use the show function:

    data Tree a = Val Integer
                | Tree a
                | Variable a
        deriving (Eq, Ord, Show)
    
    showTree :: (Show a) => Tree a -> String
    showTree = show
    

    I don’t understand your first question, so I’m just going to talk a bit in hopes that something I say helps you.

    Understand that your “tree” data type is not really a tree at all, it’s just a sum data type that can be instantiated by an integer or some type that matches the type variable, a. The second constructor, Tree, is actually not making your data type recursive – its just a constructor name in the same way Variable is a constructor name. I think you probably wanted to have subtrees (by using Tree as a type, not a constructor) – so let’s define your type as:

    data Tree a = Val Integer
                | Branch (Tree a) (Tree a)
                | Variable a
    

    Now you have a constructor named Branch that has a left and a right sub-tree. If your variables are supposed to be Strings then you certainly can use Tree String to represent this:

    myTree :: Tree String
    myTree =
        let leftBranch = Variable "x"
            rightBranch = Branch (Val 3) (Variable "y")
        in Branch leftBranch rightBranch
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my ADT: type Color = String type Hight = Integer type Width
Here's my ADT: data Ex a = I Integer --integer | Add (Ex a)
I have looked through the other questions on here, and on other forums. The
I have a program that's using adt / abstract data classes with data structures.
I use eclipse sometimes to build my android project(Using ADT 19). If i have
A simple question I'm sure, but I can't figure it out. I have some
Every One Here When i update my ADT plugin to ADT 16 i get
I have an ADT (PCB aka Process Control Block), I want to put them
I know this question has been asked here a few times before. But i
Here is my problem: I'm building an AIR package, using the mxmlc and adt

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.