Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default modules and hiding Prelude #35

Open
melrief opened this issue Aug 10, 2013 · 3 comments
Open

Default modules and hiding Prelude #35

melrief opened this issue Aug 10, 2013 · 3 comments

Comments

@melrief
Copy link
Collaborator

melrief commented Aug 10, 2013

Currently Hawk exposes some modules independently by what the user set on its configuration file (Prelude.hs). This is due to the fact that I considered those modules essential for any Haskell application. What do you think, we should keep them always loaded? The list of modules is in Config.hs, I report it here

"System.Console.Hawk.Representable"
"GHC.Num"
"GHC.Real"
"GHC.Types"
"Data.ByteString.Lazy.Char8"
"Data.Bool"
"Data.Char"
"Data.Either"
"Data.Eq"
"Data.Function"
"Data.Int"
"Data.Maybe"
"Data.Ord"

note that currently Hawk exposes Prelude with the qualification P, so if we want to have True instead of P.True we must import Data.Bool. Same for almost all the others modules. That's why I think we should keep them automatically imported. Maybe we could, in future, give an option to the user to avoid automatic loading of default modules.

The exceptions are System.Console.Hawk.Representable, that is automatically imported because Hawk cannot work without it, and Data.ByteString.Lazy.Char8 that is imported because Hawk works on (lazy) ByteStrings. Now, for the first module we can't do much, it must be loaded by default. For ByteString I don't know, if we load it in this way then many functions that are usually related to lists will be for the ByteString type. This can be misleading:

hawk -e "take 2 [1,2]"

Won't compile:
    Couldn't match expected type `Data.ByteString.Lazy.Internal.ByteString'
            with actual type `[t0]'

For me:

  • keep Prelude with qualification P. If the user wants it exposed without qualification he can set it in Prelude.hs
  • System.Console.Hawk.Representable, GHC.Num, GHC.Real, GHC.Types, Data.Bool, Data.Char, Data.Either, Data.Eq, Data.Function, Data.Int, Data.Maybe and Data.Ord should be imported by default, not matter what Prelude.hs contains. I don't know if this list of modules is enough or I missed something.
  • Data.ByteString.Lazy.Char8 should not be imported by default. The user must import it in Prelude.hs. In this way if he wants List exposed without qualification he can do that. The default Prelude.hs should import it with qualification BS
@gelisam
Copy link
Collaborator

gelisam commented Aug 11, 2013

Personally, I probably populate Prelude.hs with all those imports, including import qualified Prelude as P, so that we start with sane default yet defer absolute authority to the user. But I don't feel very strongly about the issue.

@melrief
Copy link
Collaborator Author

melrief commented Aug 11, 2013

For me it is more about how clean is the user configuration in Prelude.hs: if the user must import every single import (because Prelude will be hiddend by default) then Prelude.hs will be full of lines importing every standard type of the Haskell standard library.

If we want to let the user decide everything, even that, what do you think about creating a module called Default which exports all those modules? Like

module System.Console.Hawk.Config.Modules.Defaults (
    module System.Console.Hawk.Representable,
    module GHC.Num,
    module GHC.Real,
    module GHC.Types,
    module Data.ByteString.Lazy.Char8,
    module Data.Bool,
    module Data.Char,
    module Data.Either,
    module Data.Eq,
    module Data.Function,
    module Data.Int,
    module Data.Maybe,
    module Data.Ord
    ) where

import System.Console.Hawk.Representable
import GHC.Num
import GHC.Real
import GHC.Types
import Data.ByteString.Lazy.Char8
import Data.Bool
import Data.Char
import Data.Either
import Data.Eq
import Data.Function
import Data.Int
import Data.Maybe
import Data.Ord

the user can decide if he wants to import it or not. But he doesn't have to import every module line by line, he can just import our defaults modules. So a good Prelude.hs will be:

import System.Console.Hawk.Config.Modules.Defaults
import Control.Monad
import qualified Prelude as P

@gelisam
Copy link
Collaborator

gelisam commented Aug 11, 2013

I don't mind either way. Your choice!

– Samuel

On 2013-08-11, at 9:45 AM, Mario Pastorelli [email protected] wrote:

For me it is more about how clean is the user configuration in Prelude.hs: if the user must import every single import (because Prelude will be hiddend by default) then Prelude.hs will be full of lines importing every standard type of the Haskell standard library.

If we want to let the user decide everything, even that, what do you think about creating a module called Default which exports all those modules? Like

module System.Console.Hawk.Config.Modules.Defaults (
module System.Console.Hawk.Representable,
module GHC.Num,
module GHC.Real,
module GHC.Types,
module Data.ByteString.Lazy.Char8,
module Data.Bool,
module Data.Char,
module Data.Either,
module Data.Eq,
module Data.Function,
module Data.Int,
module Data.Maybe,
module Data.Ord
) where

import System.Console.Hawk.Representable
import GHC.Num
import GHC.Real
import GHC.Types
import Data.ByteString.Lazy.Char8
import Data.Bool
import Data.Char
import Data.Either
import Data.Eq
import Data.Function
import Data.Int
import Data.Maybe
import Data.Ord
the user can decide if he wants to import it or not. But he doesn't have to import every module line by line, he can just import our defaults modules. So a good Prelude.hs will be:

import System.Console.Hawk.Config.Modules.Defaults
import Control.Monad
import qualified Prelude as P

Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants