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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:34:15+00:00 2026-06-07T07:34:15+00:00

You don’t offen see Maybe List except for error-handling for example, because lists are

  • 0

You don’t offen see Maybe List except for error-handling for example, because lists are a bit Maybe themselves: they have their own “Nothing“: [] and their own “Just“: (:).
I wrote a list type using Maybe and functions to convert standard and to “experimental” lists. toStd . toExp == id.

data List a = List a (Maybe (List a))
    deriving (Eq, Show, Read)

toExp [] = Nothing
toExp (x:xs) = Just (List x (toExp xs))

toStd Nothing = []
toStd (Just (List x xs)) = x : (toStd xs)

What do you think about it, as an attempt to reduce repetition, to generalize?

Trees too could be defined using these lists:

type Tree a = List (Tree a, Tree a)

I haven’t tested this last piece of code, though.

  • 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-07T07:34:16+00:00Added an answer on June 7, 2026 at 7:34 am

    All ADTs are isomorphic (almost–see end) to some combination of (,),Either,(),(->),Void and Mu where

    data Void --using empty data decls or
    newtype Void = Void Void
    

    and Mu computes the fixpoint of a functor

    newtype Mu f = Mu (f (Mu f))
    

    so for example

    data [a] = [] | (a:[a])
    

    is the same as

    data [a] = Mu (ListF a)
    data ListF a f = End | Pair a f
    

    which itself is isomorphic to

    newtype ListF a f = ListF (Either () (a,f))
    

    since

    data Maybe a = Nothing | Just a
    

    is isomorphic to

    newtype Maybe a = Maybe (Either () a)
    

    you have

    newtype ListF a f = ListF (Maybe (a,f))
    

    which can be inlined in the mu to

    data List a = List (Maybe (a,List a))
    

    and your definition

    data List a = List a (Maybe (List a))
    

    is just the unfolding of the Mu and elimination of the outer Maybe (corresponding to non-empty lists)

    and you are done…

    a couple of things

    1. Using custom ADTs increases clarity and type safety

    2. This universality is useful: see GHC.Generic


    Okay, I said almost isomorphic. It is not exactly, namely

    hmm = List (Just undefined)
    

    has no equivalent value in the [a] = [] | (a:[a]) definition of lists. This is because Haskell data types are coinductive, and has been a point of criticism of the lazy evaluation model. You can get around these problems by only using strict sums and products (and call by value functions), and adding a special “Lazy” data constructor

    data SPair a b = SPair !a !b
    data SEither a b = SLeft !a | SRight !b
    data Lazy a = Lazy a --Note, this has no obvious encoding in Pure CBV languages,
    --although Laza a = (() -> a) is semantically correct, 
    --it is strictly less efficient than Haskell's CB-Need 
    

    and then all the isomorphisms can be faithfully encoded.

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

Sidebar

Related Questions

I don't know why, but this code worked for me a month ago... maybe
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't they both have to convert to machine code at some point to execute
Don't ask why, but is there any way to suppress a failed linking error?
Don't know what to do with this error. How to add data in SQL
Don't ask me why but i can't use this method because I need to
Don't immediately flag me for a duplicate question. My issue is different because I
Don't know why this conversion fails. SELECT CAST('32.999' AS INT) throws the error saying
Don't think this is a repost, difficult to search for the word between because
don't know if the title describes anything about what I'm trying to say but

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.