[Haskell] overuse of maybe and [] in prelude and libs
S. Alexander Jacobson
alex at i2x.com
Thu Apr 8 14:11:20 EDT 2004
> Actually Haskell doesn't let you redefine *everything*, but GHC does:
> read section 7.3.5 of the GHC manual
> http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.htm
> l#REBINDABLE-SYNTAX
Mostly. It looks like you still can't redefine
Monad to have an Ord or EQ constraint.
In particular, it is essential that the
functions GHC finds in scope must have the
appropriate types, namely:
(>>=) :: forall m a. (...) => m a -> (a -> m b) -> m b
But, either way, I'm assuming I can't do this
(making up syntax):
import Data.FiniteMap using MyPrelude as Prelude
So that every place in FiniteMap that Prelude
functions are called, MyPrelude functions are
called instead? Then I could simply redefine just
and nothing as return and mzero.
Aside: I assume that FiniteMap's lookupFM, like
lookup in the Prelude calls Constructor literals
(e.g. Just, Nothing) rather than functions that
call these literals (e.g. just=Just,
nothing=Nothing) so in practice this import
function wouldn't help me as much as I would like.
But, I wonder if exposing constructor literals is
actually bad style. Should good libraries hide
their constructors and expose only:
* functions that implement construction (e.g. just)
* functions that provide dispatch on each
constructor (e.g. foldr, maybe, either, etc)
Or is this too restrictive? Is the prelude good
style even though it exports Just and Nothing?
-Alex-
_________________________________________________________________
S. Alexander Jacobson mailto:me at alexjacobson.com
tel:917-770-6565 http://alexjacobson.com
On Thu, 8 Apr 2004, Simon Peyton-Jones wrote:
>
> | > Haskell is pretty good about letting you install a different
> Prelude, so you could try it yourself.
> |
> | Hmm. That's interesting! How does this work?
>
> It's very simple. Write your own Prelude as a Haskell module MyPrelude.
>
> Then to use it, say
> module Foo where
> import Prelude ()
> import MyPrelude
>
> (GHC lets you omit the 'import Prelude ()' by saying
> -fno-implicit-prelude.)
>
> No, there is no auto-magic; you are simply getting a different library,
> that is all. And you have to write that library.
>
> No problem with some modules using MyPrelude and some using Prelude.
> (Any more than there's a problem when some modules import module A and
> some import module B.)
>
>
>
> Simon
>
>
More information about the Haskell
mailing list