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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:32:25+00:00 2026-06-12T14:32:25+00:00

Suppose I’d want to create a new data type and make the constructors showable,

  • 0

Suppose I’d want to create a new data type and make the constructors showable, only in lower case instead of their upper case definition. For example:

data Day = Monday | Tuesday | Wednesday| Thursday | Friday | Saturday | Sunday

By adding deriving Show, ghci would print them as “Monday, Tuesday.. etc.” To get it to show “monday, tuesday.. etc” I’ve tried to make a special instance of show:

import Data.Char

strToLower :: [Char] -> [Char]
strToLower (x:xs) = toLower x : strToLower xs
strToLower [] = []

instance Show Day where
   show d = strToLower (show d)

where the first occurrence of show should designate my new amended show function (which will be called everytime I print) whereas for the second I intend the normally derived version of show, to get from the constructor name to a String.

Of course this doesn’t work (circular definition) as the ghci has no clue to my separate meanings of the word “show” but I can’t figure out how to let him know the distinction, for both versions need to be named show, the first because that’s what print calls to and the second because it’s a predefined haskell function which can give me a String out of a constructor name. I’ve tried

show d = strToLower ((showsPrec 0 d) "")

but this comes down to the same circular definition, at least that’s what I guess from the ghci getting stuck in a loop.

I understand why constructor names need to begin with an upper case letter, but showing them lower case shouldn’t be a problem, should it? I know I could just define my show function for every case separately, e.g. show Monday = "monday" show Tuesday = "tuesday" etc, but I’m only using the days of the week as an example here and my real data type consists of 64 constructors so I think it would be more elegant to solve it differently somehow.

Is it possible to dig into the haskell definition of show and alter a copy of that code? This is the only possible solution I can think of but I don’t know how to do it, if it is possible at all. Probably not. So other solutions are very welcome as well!

Thank you for taking your time,

Jelle (Haskell beginner)

  • 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-12T14:32:27+00:00Added an answer on June 12, 2026 at 2:32 pm

    You can actually do this using the Typeable and Data classes.

    To do this you need the DeriveDataTypeable extension, turn it on with -XDeriveDataTypeable or by putting the following line at the start of the file that defines your type:

    {-# LANGUAGE DeriveDataTypeable #-}
    

    You can now import the needed modules:

    import Data.Data
    import Data.Typeable
    

    And derive Typeable and Data:

    data Day = Monday | Tuesday | Wednesday| Thursday | Friday | Saturday | Sunday
         deriving (Typeable, Data)
    

    Now you can use toConstr to get a constructor representation:

    instance Show Day where
       show = strToLower . showConstr . toConstr
    

    But see the other answers on whether you’d really want to, instead of simply using a showDay function or your own type class instead.

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

Sidebar

Related Questions

Suppose I have defined a unit of measure: [<Measure>] type Blob And I want
Suppose there is a data field education in my table profile, now I want
Suppose I declare a new C++ struct type: struct my_struct { int a; int
Suppose I created index with descending order CREATE INDEX `MyTable.MyIndex` USING BTREE ON `MyTable`
Suppose you create a class names Person using the builder pattern, and suppose the
Suppose I have a superclass Item and a subclass MovingItem. If I create an
Suppose we have the following: data Foo x from_list :: [x] -> Foo x
Suppose I have a data frame, df, that looks like: f t1 t2 t3
Suppose a mysql 5.5 server uses the following configuration for storing innodb data innodb_data_file_path
Suppose a process spawns a thread A and this thread further spawns a new

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.