0

I'm new to Haskell. I was reading the code here and I'm not sure (though I can guess) what uses do:

inRange <- uses fsCurrentCoinRangeUpperBound (coinIndex <=)

Also, why's <- been used?

I've looked up for "Control lens uses in Haskell" but I couldn't find any explanation.

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
user4564798
  • 97
  • 10
  • 1
    You have read the [_documentation_ on `uses`](http://hackage.haskell.org/package/lens-4.15.3/docs/Control-Lens-Getter.html#v:uses), and know how to [generally find documentation](https://hayoo.fh-wedel.de/?query=uses)? It makes very seldom sense to rely on Google for finding out about some Haskell function, the specific engines Hoogle and Hayoo are much better. – leftaroundabout Jun 29 '17 at 12:23
  • @leftaroundabout Thanks for the tip! – user4564798 Jun 29 '17 at 12:27
  • Another option for navigating docs faster - and offline - is Dash or Zeal – nicolas Jun 29 '17 at 12:30
  • @nicolas the default Zeal database on Haskell isn't particularly complete though – is there an easy way to extend it, or Dash's? Else I'd say a local Hoogle together with locally-install haddocks is more useful for offline help, since it works for any installed package. – leftaroundabout Jun 29 '17 at 12:44
  • @leftaroundabout You can use haddocset https://github.com/philopon/haddocset/ works great for me. I wish stackage would generate that automatically – nicolas Jun 29 '17 at 13:10

2 Answers2

1

The first hit for a Google search on "haskell control.lens" gives me this:

https://hackage.haskell.org/package/lens-4.15.3/docs/Control-Lens.html

...the documentation for the Lens package where the uses function comes from. From there, it's not actually straight-forward to determine which exact module defines this function. It turns out it's Control.Lens.Getter:

https://hackage.haskell.org/package/lens-4.15.3/docs/Control-Lens-Getter.html#v:uses

So that's how you track down the documentation for random Haskell functions. Whether that documentation is actually helpful varies considerably...

MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
  • Thank you very much! I had a look at it, but I didn't know it was part of "Getter". – user4564798 Jun 29 '17 at 12:26
  • 1
    Thinking about it, you could perhaps have discovered that by asking GHCi with the `:i` command. I hadn't thought of that. (I don't have this package installed myself.) – MathematicalOrchid Jun 29 '17 at 12:27
  • This is a big shortcoming of the `lens` docs, in my opinion. It's difficult to tell where a given combinator comes from. I'd love there to be a big "index" page with every combinator listed out, so you can cmd-F and find the one you're looking for. – Benjamin Hodgson Jun 29 '17 at 13:00
  • 3
    Uh. You guys are aware of haddock index pages, right? https://hackage.haskell.org/package/lens-4.15.3/docs/doc-index-All.html – Carl Jun 29 '17 at 13:59
  • 1
    @Carl I am now! Thanks, this is exactly what I had in mind :) – Benjamin Hodgson Jun 29 '17 at 16:00
0

The documentation is the type + haddoc extra bits, and vice versa.

For instance we can see

uses :: MonadState s m => LensLike' (Const r) s a -> (a -> r) -> m r

That the return value is like a burrito (hence the <-. which gives you the current filling to grow a bigger burrito)

nicolas
  • 9,549
  • 3
  • 39
  • 83