Skip to content

Handle active region case better in haskell-process-show-type-at #701

Closed
@geraldus

Description

@geraldus

The :type-at command works fine when you ask a type for several line, for example

main :: IO ()
main =
  do let x = "Hello, World!"
     putStrLn x

following command will infer type for region starts from do and ends at x on the next line:

λ> :type-at /Users/arthurfayzrakhmanov/Haskell/test/HelloWorld.hs 3 3 4 16
:: IO ()

and even without x:

λ> :type-at /Users/arthurfayzrakhmanov/Haskell/test/HelloWorld.hs 3 3 4 15
 :: String -> IO ()

The function show-type-at works fine and returns correct results in these cases (active region wrapping several lines), the only caveat is that currently it passes marked expression as fifth argument to type at command and it confuses REPL and brings errors:

Haskell presentation buffer contents:

do let x = "Hello, World!" :: String -> IO ()

<interactive>:50:6-13:
    No instance for (Show (String -> IO ()))
      arising from a use of print
    In a stmt of an interactive GHCi command: print it

Haskell process log contents:

-> :type-at /Users/arthurfayzrakhmanov/Haskell/test/HelloWorld.hs 3 3 4 14 do let x = "Hello, World!"
     putStrLn

<- do let x = "Hello, World!" :: String -> IO ()

   

   <interactive>:50:6-13:

       No instance for (Show (String -> IO ()))

         arising from a use of print

       In a stmt of an interactive GHCi command: print it

The fifth argument of :type-at is optional and plays auxiliary role:

λ> :type-at /Users/arthurfayzrakhmanov/Haskell/test/HelloWorld.hs 3 3 4 15 "TEST"
"TEST" :: String -> IO ()
λ> :type-at /Users/arthurfayzrakhmanov/Haskell/test/HelloWorld.hs 3 3 4 15 WHAT?
WHAT? :: String -> IO ()

So we have at least two options to make world better:

  • reduce expression using haskell-utils-reduce-string1 before pass it to :type-at command
  • reduce expression like haskell-mode-message-line2 does
  • replace multiline and long expressions with
  • replace long expressions with some arbitrary string, such as "expr".

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions