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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:19:16+00:00 2026-05-18T20:19:16+00:00

I must write a function to_string wich receives this datatype datatype prop = Atom

  • 0

I must write a function “to_string” wich receives this datatype

datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;

and returns a string.

Example

show
And(Atom(“saturday”),Atom(“night”)) =
“(saturday & night)”

My function is working but I have 2 problems.

  1. the interpreter tells me -> Warning: match nonexhaustive
  2. I think i can write the function with locals functions for all the types (Not, And, Or) and avoid duplicate code but I don’t know how.

there is my code

datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop;

fun show(Atom(alpha)) = alpha
    | show(Not(Atom(alpha))) = "(- "^alpha^" )"

    | show(Or(Atom(alpha),Atom(beta)))  = "( "^alpha^" | "^beta^" )"
    | show(Not(Or(Atom(alpha),Atom(beta)))) = "(- ( "^alpha^" | "^beta^" ))"
    | show(Or(Not(Atom(alpha)),Atom(beta)))  = "( (-"^alpha^") | "^beta^" )"
    | show(Or(Atom(alpha),Not(Atom(beta))))  = "( "^alpha^" | (-"^beta^") )"
    | show(Or(Not(Atom(alpha)),Not(Atom(beta))))  = "( (-"^alpha^") | (-"^beta^") )"


    | show(And(Atom(alpha),Atom(beta))) = "( "^alpha^" & "^beta^" )"
    | show(Not(And(Atom(alpha),Atom(beta)))) = "(- ( "^alpha^" & "^beta^" ))"
    | show(And(Not(Atom(alpha)),Atom(beta))) = "( (-"^alpha^") & "^beta^" )"
    | show(And(Atom(alpha),Not(Atom(beta)))) = "( "^alpha^" & (-"^beta^") )"
    | show(And(Not(Atom(alpha)),Not(Atom(beta))))  = "( (-"^alpha^") & (-"^beta^") )";

Thanks a lot for 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-05-18T20:19:16+00:00Added an answer on May 18, 2026 at 8:19 pm

    The general rule is as follows: if you have a recursive data type, you should use a recursive function to transform it.

    Your match expression is not exhaustive because there are a lot of variants you can’t handle – i.e. And(And(Atom(“a”), Atom(“b”)), Atom(“c”)).

    You should rewrite the function with recursive calls to itself – i.e. replace Not(Atom(alpha)) match with Not(expr):

    show(Not(expr)) = "(- " ^ show(expr) ^ " )"
    

    I’m sure you can figure out the rest (you’ll have two recursive calls for and/or).

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

Sidebar

Related Questions

I must write a function to_string wich receives this datatype datatype prop = Atom
i write row click handler: $('#mTable tr').unbind().live('click', function() { //specialFunction() }); specialFunction must not
Can PHP dissect its own syntax? For example, I'd like to write a function
I need to write a split function in JavaScript that splits a string into
I'm trying to write a function that formats every (string) member/variable in an object,
I am using the StringOfChar function to create a string of chars like this
I need to write a function that will concatenate a list into a string.
I want to write a procedure (function) that checks if a string contains another
Trying to write such function. It must divide text into multiple columns and the
I'm interested in not having to write map the int function to the tuple

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.