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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:24:40+00:00 2026-06-12T02:24:40+00:00

In Haskell, I write import Fruit or import Fruit (apple) and can access apple

  • 0

In Haskell, I write import Fruit or import Fruit (apple) and can access apple or Fruit.apple.

In Python, I can write from Fruit import apple for apple or import Fruit for Fruit.apple.

I think can also write import Fruit.apple as banana in Python to reference the same function as banana.

How, in Haskell can I do this? import Fruit as Vegetable in either language can rename Fruit, but I want to rename apple.

  • 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-12T02:24:41+00:00Added an answer on June 12, 2026 at 2:24 am

    This is a nice property Python has because its “dictionaries all the way down,” so to speak.
    Haskell allows you to assign aliases to modules, but there is no way to alias functions
    from the import statement (as far as I know). The best you would be able to do is

    import qualified Fruit as F (apple)
    banana = F.apple
    

    You could put this in its own module and export the values you want, hiding the details of all this, but that seems like a lot of work for something so simple.

    As commented below by hammar, the monomorphism restriction could cause trouble with the inferred type
    of banana. To be safe, you should either annotate banana with its desired type (probably that of apple), or disable the monomorphism restriction as

    {-# LANGUAGE NoMonomorphismRestriction #-}
    import qualified Fruit as F (apple)
    banana = F.apple
    

    Otherwise, the inferred type of banana could be less polymorphic than desired.

    The Monomorphism restriction attempts to assign a concrete instance of a type class for each top level function (this is done for performance reasons). Consider,

    example = return ()
    

    This function should have type Monad m => m (), but due to the monomorphism restriction, there is not enough information about which Monad instance should be used, so you get the following message

    Ambiguous type variable `m0' in the constraint:
      (Monad m0) arising from a use of `return'
    Possible cause: the monomorphism restriction applied to the following:
      example :: m0 () (bound at Test.hs:44:1)
    Probable fix: give these definition(s) an explicit type signature
                  or use -XNoMonomorphismRestriction
    In the expression: return ()
    In an equation for `example': example = return ()
    

    Now, if you provide enough information for GHC to infer which instance of Monad you are using, such as

    example = return ()
    
    main :: IO ()
    main = example
    

    then GHC will give the following type

    *Main> :t example
    example :: IO ()
    

    since you told it that example will have the same type as main

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

Sidebar

Related Questions

How can I write a function in Haskell, that takes an input string in
I need to write a haskell program that retrieves a file from command line
I'm trying to write a Haskell function that checks if a list of integers
I'm playing around with beginner Haskell, and I wanted to write an average function.
I'm learning Haskell and am trying to write code as fast as I can
I'm so proud of myself! ^_^ I can finally write Haskell functions that work!
I'm trying to write a Haskell append function... Here's what I have: myappend ::
What I want is to write a Haskell function to return the files of
I am trying to write haskell function that takes list of lists and find
I'm trying to write a haskell function that takes in two lists of integers

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.