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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:40:14+00:00 2026-06-10T16:40:14+00:00

I’ve just started playing a little with Haskell… I want to write a function

  • 0

I’ve just started playing a little with Haskell… I want to write a function of the same type of the identity. Obviously, not equivalent to it. That would be something like,

myfunction :: a -> a

I cannot come up with an example in which the parameter and the return type are the same and can be virtually anything (this excludes the possibility of using Haskell’s Typeclasses).

  • 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-10T16:40:16+00:00Added an answer on June 10, 2026 at 4:40 pm

    This is impossible without using undefined as another commenter mentioned. Let’s prove it by counter-example. Assume there were such a function:

    f :: a -> a
    

    When you say that’s it not the same as id, that implies that you cannot define:

    f x = x
    

    However, consider the case where a is the type ():

    f () = ...
    

    The only possible result f could return would be (), but that would be the same implementation as id, therefore a contradiction.

    The more sophisticated and rigorous answer is to show that the type a -> a must be isomorphic to (). When we say two types a and b are isomorphic, that means that we can define two functions:

    fw :: a -> b
    bw :: b -> a
    

    … such that:

    fw . bw = id
    bw . fw = id
    

    We can easily do this when the first type is a -> a and the second type is ():

    fw :: (forall a . a -> a) -> ()
    fw f = f ()
    
    bw :: () -> (forall a . a -> a)
    bw () x = x
    

    We can then prove that:

    fw . bw
    = \() -> fw (bw ())
    = \() -> fw (\x -> x)
    = \() -> (\x -> x) ()
    = \() -> ()
    = id
    
    bw . fw
    = \f -> bw (fw f)
    -- For this to type-check, the type of (fw f) must be ()
    -- Therefore, f must be `id`
    = \f -> id
    = \f -> f
    = id
    

    When you prove two types are isomorphic, one thing you know is that if one type is inhabited by a finite number of elements, so must the other one. Since the type () is inhabited by exactly one value:

    data () = ()
    

    That means that the type (forall a . a -> a) must also be inhabited by exactly one value, which just so happens to be the implementation for id.

    Edit: Some people have commented that the proof of the isomorphism is not sufficiently rigorous, so I’ll invoke the Yoneda lemma, which when translated into Haskell, says that for any functor f:

    (forall b . (a -> b) -> f b) ~ f a
    

    Where ~ means that (forall b . (a -> b) -> f b) is isomorphic to f a. If you choose the Identity functor, this simplifies to:

    (forall b . (a -> b) -> b) ~ a
    

    … and if you choose a = (), this further simplifies to:

    (forall b . (() -> b) -> b) ~ ()
    

    You can easily prove that () -> b is isomorphic to b:

    fw :: (() -> b) -> b
    fw f = f ()
    
    bw :: b -> (() -> b)
    bw b = \() -> b
    
    fw . bw
    = \b -> fw (bw b)
    = \b -> fw (\() -> b)
    = \b -> (\() -> b) ()
    = \b -> b
    = id
    
    bw . fw
    = \f -> bw (fw f)
    = \f -> bw (f ())
    = \f -> \() -> f ()
    = \f -> f
    = id
    

    So we can then use that to finally specialize the Yoneda isomorphism to:

    (forall b . b -> b) ~ ()
    

    Which says that any function of type forall b . b -> b is isomorphic to (). The Yoneda lemma provides the rigor that my proof was missing.

    • 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 need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

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.