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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:28:39+00:00 2026-06-04T13:28:39+00:00

I’ve already asked the question about undefined . And because it is impossible to

  • 0

I’ve already asked the question about undefined. And because it is impossible to do such thing, I will describe the case when this can be useful. But I think the question is common and can be useful in other cases.

Lets imagine a situation, when we write a parser for some grammar. We’ve defined AST implemented by many data-types, each of them has a set of constructors, each constructor has a set of parameters. Every type derives from Show. Then we begin to write parser realization, where we define many functions with recursive dependences.

As we have many functions, its hard to write a whole module at once without a check. But functions circular reference won’t allow to compile the unfinished module. In this case I define hook functions that do nothing expect returning value of the type needed.

And here is a problem! Function must return not a simple type, but a data constructor with constructors in constructors. This is too hard for a hook function. So I do this:

parseHook _ = undefined

And everything is simple till “undefined” is not in the result data tree. I want to point out that this situation happens in developing stage and that the only thing I want is to see the tree structure. Of course, I can wrap every type in “Maybe”, but I dont want to change already existing types.

English is not my native language, so Im not sure that I’ve expressed my thoughts correctly. That’s why I want to add an example of this situation:

data StructParam = StructParam Int Int
                 deriving Show 

data Struct1 = Struct1 Int Int StructParam Int Int Int Int StructParam
             deriving Show 

data Struct2 = Struct2 Int Int StructParam Int Int Int Int StructParam  
             deriving Show 

data Struct3 = Struct3_var1 Struct1 
             | Struct3_var2 Struct2
             deriving Show 

-- this hook is ok, but too long
parse1 _ = Struct1 1 2 (StructParam 3 4) 5 6 7 8 (StructParam 9 0)

-- this hook is short, but undefined
parse2 _ = undefined

-- complete function
rootParse 1 = Struct3_var1(parse1 1)    
rootParse 2 = Struct3_var2(parse2 2)

>print $ rootParse 1
Struct3_var1 (Struct1 1 2 (StructParam 3 4) 5 6 7 8 (StructParam 9 0))

>print $ rootParse 2
Prelude.undefined

-- but I want something like this
>print $ rootParse 2
Struct3_var2("undefined")
  • 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-04T13:28:40+00:00Added an answer on June 4, 2026 at 1:28 pm

    You could add “Unimplemented” as a constructor in your data type, have a default case for all parses that ends in a definition of Unimplemented, and then the show instance will work trivially.

    data Exp = Literal Int
             | Variable String
             | Operator Op Exp Exp
             | Unimplemented
    
        deriving Show
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.