8

How can I use the hoogle command line flags when using hoogle inside ghci?

This obviously doesn't work:

ghci> :hoogle --count=5 Char -> Int
Could not read as type Int, "5 Char -> Int"
sjakobi
  • 3,546
  • 1
  • 25
  • 43

1 Answers1

7

You need to change your ghci.conf in order to do this. Assuming you did the steps described on haskell.org, your ghci.conf contains a line like

:def hoogle \x -> return $ ":!hoogle \"" ++ x ++ "\""

However, that line says that :hoogle x will be translated to hoogle "x", which obviously won't work if you want to apply additional flags, such as --count=5.

You either need to remove the quotes around the argument, e.g.

:def hoogleP \x -> return $ ":!hoogle " ++ x

and use :hoogleP --count=5 "Char -> Int" or split the argument by hand into count and search query:

:def hoogleC \x -> return $ ":!hoogle --count="++(head.words $x)++" \"" ++ (unwords.tail.words $x) ++ "\""

The last version can be used as :hoogleC 5 Char -> Int.

Zeta
  • 103,620
  • 13
  • 194
  • 236
  • If hoogleC would employ `unwords` instead of `concat`, this wouldn't happen:`ghci> :hoogleC 1 Maybe a -> a Warning: Unknown type Maybea Unsafe.Coerce unsafeCoerce :: a -> b` – sjakobi Feb 14 '14 at 23:42
  • Thanks for writing your answer and updating it! It's super useful! – sjakobi Feb 16 '14 at 18:27