Bikeshedding request for GHCi's :type
Christopher Allen
cma at bitemyapp.com
Wed Apr 27 17:25:01 UTC 2016
I agree with Iavor that :type should report the real type. I see this only stymieing and frustrating efforts to teach the language.
I do like the :inst idea.
> On Apr 27, 2016, at 12:22 PM, Iavor Diatchki <iavor.diatchki at gmail.com> wrote:
>
> Hello Richard,
>
> I think that `:type` should report the real type of an expressions (i.e., the fully generalized inferred type, just like it does now). Certainly I wouldn't want `:type` to show me some kind of (more or less) arbitrary specialization of the type.
>
> It could be useful to have a ghci command that would show all instantiations of a class method (just 1 level deep) using the instances that are currently in scope. This would be essentially a combination of `:info` on a class and a method. For example, this is what it would look like on some of the methods in 7.10's Prelude:
>
> :inst length
> length :: [a] -> Int
> length :: Maybe a -> Int
> length :: Either a b -> Int
> length :: (a,b) -> Int
>
> :inst (==)
> (==) :: Integer -> Integer -> Bool
> (==) :: Word -> Word -> Bool
> ...
> (==) :: Eq a => [a] -> [a] -> Bool -- Note that we only instantiate the outer class
> ...
> (==) :: (Eq a, Eq b, Eq c) => (a,b,c) -> (a,b,c) -> Bool -- ditto
>
> :inst mapM
> mapM :: Monad m => (a -> m b) -> [a] -> m [b]
> mapM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
> mapM :: Monad m => (a -> m b) -> Either e a -> m (Either e b)
> mapM :: Monad m => (a -> m b) -> (e,a) -> m (e,b)
>
> This could be generalized to expressions, rather than just methods, but for expressions with multiple constraints one could get an explosion of possible instantiations. However, it would be quite cool to allow things like this:
>
> :inst 1
> 1 :: Word
> 1 :: Integer
> 1 :: Int
> 1 :: Float
> 1 :: Double
>
> Anyway, just some ideas.
>
> -Iavor
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Wed, Apr 27, 2016 at 8:16 AM, Manuel Gómez <targen at gmail.com <mailto:targen at gmail.com>> wrote:
> On Wed, Apr 27, 2016 at 10:15 AM, John Leo <leo at halfaya.org <mailto:leo at halfaya.org>> wrote:
> > Speaking as someone teaching his coworkers Haskell now, Eric's is the best
> > suggestion I've seen so far.
> >
> > What I like about it:
> > * The original meaning of :type is unchanged.
> > * No new command is added (I prefer adding a flag to adding another
> > command).
> > * With the flag on, the full type is shown along with the possible
> > specializations (and good to note the list might not be exhaustive). This
> > way, beginners can still see what the type should look like even if they
> > want to ignore it for now. This is similar to learning to read Japanese by
> > using furigana. It may be a bit confusing for beginners at first, but I
> > expect they'll quickly learn to ignore it until they need it, and I agree it
> > will be useful for experienced Haskellers.
>
> Perhaps a pleasant solution would be to borrow a convention from the
> PostgreSQL community's interactive console psql and its meta-commands:
> http://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-META-COMMANDS <http://www.postgresql.org/docs/current/static/app-psql.html#APP-PSQL-META-COMMANDS>
>
> For example:
>
> > \d[S+] [ pattern ]
> >
> > For each [object] matching the pattern, show all columns, their types, the tablespace (if not the default) and any special attributes such as NOT NULL or defaults. […] The command form \d+ is identical, except that more information is displayed: any comments associated with the columns of the table are shown, as is the presence of OIDs in the table, the view definition if the relation is a view, a non-default replica identitysetting.
>
> Many psql commands use this convention: add a + to the end of the
> command, and you get extra information. It’s quite nmemonic.
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org <mailto:ghc-devs at haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs <http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs>
>
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20160427/8e84a4ec/attachment.html>
More information about the ghc-devs
mailing list