Opened 5 years ago

Last modified 3 years ago

#9748 new feature request

Disambiguate IO actions in GHCi with :set +t

Reported by: Iceland_jack Owned by:
Priority: low Milestone:
Component: GHCi Version: 7.8.2
Keywords: Cc: hvr
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Currently GHCi's :set +t displays the same type for the following:

% ghci -ignore-dot-ghci
GHCi, version 7.8.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :set +t
Prelude> 'a'
'a'
it :: Char
Prelude> return 'a'
'a'
it :: Char
Prelude> return 'a' :: IO Char
'a'
it :: Char

A user at #haskell-beginners ran into a problem where they mistook an expression that defaulted to IO for a pure expression (Id . even <$> pure 5), :set +t was suggested but ended up showing the incorrect type:

ghci> Id . even <$> pure 5
Id False
it :: Id Bool

This is bad for pedagogical reasons, it would be an improvement to display the following:

Prelude> :set +t
Prelude> 'a'
'a'
it :: Char
Prelude> return 'a'
'a'
it :: Char <- return 'a' :: IO Char
Prelude> return 'a' :: IO Char
'a'
it :: Char <- return 'a' :: IO Char

mirroring existing syntax:

Prelude> :set -XScopedTypeVariables 
Prelude> a :: Char <- return 'a' :: IO Char
a :: Char

Change History (8)

comment:1 Changed 5 years ago by Iceland_jack

*showing the incorrect type for the given expression, the type of it is correct.

comment:2 Changed 5 years ago by hvr

I've been wishing something like that myself, however I don't like

it :: Char <- return 'a' :: IO Char

as it's too noisy IMO by the redundantly repeated value's type

I'd rather like to see something like

it :: {- IO -} Char

that doesn't need to repeat the type, and still give an indication about evaluated result stored in it having resulted from an IO-action

comment:3 Changed 5 years ago by simonpj

Moreover we really don't want to repeat the expression being evaluated, which might be large! Way too noisy.

I quite like Herert's suggestion. Or

Prelude> return 'a'
Running IO action...
'a'
it :: Char

or

Prelude> return 'a'
it :: Char  -- After running the IO action

comment:4 Changed 5 years ago by zudov

Owner: set to zudov

comment:5 in reply to:  3 Changed 5 years ago by hvr

Replying to simonpj:

I quite like Herert's suggestion. Or

Prelude> return 'a'
Running IO action...
'a'
it :: Char

This has the risk of interleaving with other side-effected output the IO action may produce

or

Prelude> return 'a'
it :: Char  -- After running the IO action

This has the issue of introducing an English sentence which may require translation to other language (should GHCi ever be i18n'ed), as well as using up precious horizontal space for a boilerplate expression. I'd rather avoid adding natural language in places where a more terse annotation would suffice

comment:6 Changed 5 years ago by thomie

I like Herbert's suggestion too. See #7727 for a user report which could have been prevented if this feature got implemented.

comment:7 Changed 4 years ago by zudov

Owner: zudov deleted

comment:8 Changed 3 years ago by Iceland_jack

Note: See TracTickets for help on using tickets.