Jakub Arnold | 24 Jan 04:54 2014
Picon

How does one read complicated type signatures?

Hello world,

I’ve just started playing with the http-conduit package and started inspecting type signatures of some of the functions, and I stumbled upon many things that look like this

*Main Network.HTTP.Conduit> :t withManager
withManager
  :: (monad-control-0.3.2.2:Control.Monad.Trans.Control.MonadBaseControl
        IO m,
      transformers-0.3.0.0:Control.Monad.IO.Class.MonadIO m) =>
     (Manager
      -> resourcet-0.4.10:Control.Monad.Trans.Resource.Internal.ResourceT
           m a)
     -> m a

The question is … how am I supposed to read these? It seems that they wrap around (maybe) 80 characters, which makes them unreadable … and the package prefixes also don’t really help.

I’d like to point out here that I’m really a noob without any practical experience in Haskell, I’ve just read a few books. So I don’t have a problem understanding the concepts, but more and more often I find myself struggling just to read the type signature correctly

Thanks for any tips, Jakub
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Brandon Allbery | 24 Jan 05:12 2014
Picon

Re: How does one read complicated type signatures?

On Thu, Jan 23, 2014 at 10:54 PM, Jakub Arnold <darthdeus <at> gmail.com> wrote:
*Main Network.HTTP.Conduit> :t withManager
withManager
  :: (monad-control-0.3.2.2:Control.Monad.Trans.Control.MonadBaseControl
        IO m,
      transformers-0.3.0.0:Control.Monad.IO.Class.MonadIO m) =>
     (Manager
      -> resourcet-0.4.10:Control.Monad.Trans.Resource.Internal.ResourceT
           m a)
     -> m a

The question is … how am I supposed to read these? It seems that they wrap around (maybe) 80 characters, which makes them unreadable … and the package prefixes also don’t really help.

Import the modules named (usually ignoring any "Internal" or "Class" part), and their names will shorten. Since the names aren't in scope in ghci, it's being specific about where it found them.

  (MonadBaseControl IO m, MonadIO m) => (Manager ResourceT m a) -> m a

should be what you see with Control.Monad.Trans.Control, Control.Monad.Trans (because I happen to know the "public" export of MonadIO is there), and Control.Monad.Trans.Resource in scope.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b <at> gmail.com                                  ballbery <at> sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane