I am a beginner in Haskell, and I want to understand Reader Monad. I know how to use this monad. But I want to see the implementation of monad (particularly code of function "return"). How can I see this code?
Answered in the comments by pdexter:
The definition is here but I would recommend reading the simplified version here.
I have downloaded the ghc source from here
It contains the definition of all the base functions
Then I open the folder in Sublime text editor which will index the source files. Then you can type F12 on a function or Ctrl+Shift+F to find the implementation. You can jump back with Alt+-.
I actually downloaded many other Haskell libraries for easy reference.
Related
I've attempted to comb the repository (oh the joys of globally used single character names) without luck, but maybe I'm looking for the wrong things.
Seeing documentation for SDL.P would probably also work.
For future reference, is there a good way to go about finding data constructors in Haskell (as they seem to be difficult to grep for in the single-character case)?
Hackage has haddocks for the sdl2 package. If you click the "Index" link, then click "P", you can find a list of all identifiers that start with that letter -- including the P data type.
http://hackage.haskell.org/package/sdl2-2.4.1.0/docs/doc-index-P.html
Is this it? It’s all I could find using stackage search within the “sdl2” package.
https://www.stackage.org/haddock/lts-12.13/sdl2-2.4.1.0/SDL-Internal-Vect.html#v:P
Edit, how I did it:
You can limit the search offered by Stackage to a single package, using the URL: https://www.stackage.org/package/PACKAGE_NAME, so in this case https://www.stackage.org/package/sdl2.
Searching for operators, put them in parentheses, such as "(.)". For your question, search for "P" like so: https://www.stackage.org/lts-12.13/hoogle?q=P&package=sdl2
I want to use a PureScript in the program code to generate text of JavaScript from it. For example, I use Julius (from Yesod) to directly insert a javascript. I want to use the same PureScript .Maybe there are such solutions or libraries?
Thank you!
When I have done something similar, I've kept the Purescript source in separate files, and combined the Haskell & Purescript parts later (during the build or at runtime). I think this is the easiest way, and you can keep using existing Purescript tools.
I had my web server read the JS output from purs at runtime. Another option would be to use file-embed to include the JS text when compiling the Haskell code. One reason to prefer file-embed is if you need to have a single executable file to deploy.
Finally, I have a Makefile that builds the Purescript code, then the Haskell code.
I’m running racket as a repl (with xrepl), and I’m able to use ,doc to see some relevant documentation (almost awesome), but it fires up a web browser to see the documentation. I’d like to be able to see the docs right in the repl, similarly to how it’s presented in other repls (R, Clojure, ipython, pry, etc). Is this possible?
E.g., in Clojure’s lein repl, one can do:
user=> (doc map)
-------------------------
clojure.core/map
([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
Returns a lazy sequence consisting of the result of applying ...
It would also be great to be able to see source ((source map) in clojure), but I haven’t seen any hints of this being available.
I happen to be using Vim (with slime/tmux), so any Vim-based solution would also work, probably tied to its K built-in help.
I'm not sure this is practical given the nature of Racket documentation.
The help deliverable is HTML.
Unlike Clojure (or Emacs Lisp), Racket doesn't have doc strings in the function definition source.
Racket docs don't have a convention like the one that the first line of a doc string should be a summary (a short-version to use in situations like a list of commands or in a REPL).
You can try xrepl's ,desc <id> command. Starting in Racket 6.1.1, if the function has installed documentation, it will print a rendering of the "blue box" -- the function signature with contracts and/or types. In many cases that's all you need, say to jog your memory. However there is no text describing the item. And if there is no installed help for a function, it won't attempt to show you anything based on the function's definition source.
So for example in racket-mode for Emacs, there is a racket-describe command and it does not fire up a browser -- but it shows the full HTML help (if any) using shr in a separate Emacs buffer. If there is no help, it does try to find the source and extract a contract/type and signature to show you. But again, there is no doc string in that source, to find, much less a one-line summary to show neatly in a REPL.
There are vim fans using Racket; the ones I know are use evil-mode in Emacs and feel it's the best of both worlds. However I appreciate that's not your current workflow using multiple languages, so I'm not proposing that as the solution for you.
I put together VROD, a solution that parses the reference documentation into something that Vim can work with. This provides essentially what you can get from clojure's doc built-in help, but through Vim’s K-help. And it also does some highlighting and shows examples.
(It also happens to do auto-completion of functions.)
I have googled extensively, and while I can find many examples of cabal files as well as good tutorials, I would like to have a proper grammar definition for the .cabal file format. Alas, I have not been able to find it. The more recent cabal documentation only mentions that its file format is backwards compatible -- with no links to the 'original' format with which it is compatible! Not useful.
a proper grammar definition for the .cabal file format.
The grammar is defined by its parser. I don't know of a formal specification.
Is this what you want?
Distribution.PackageDiscription
The list of the fields, whether they are required or not, and what goes in them is here https://www.haskell.org/cabal/users-guide/developing-packages.html#package-properties.
Not the most obvious of places, I must admit.
everyone, i'm pretty new to haskell. i was a c++ programmer.
how to find a detailed list of functions in a particular module such like in the default "prelude" module? and how to find out how these functions work in ghci environment?
ie. is there a command to find out all functions in "Prelude"?
Thanks.
how to find a detailed list of
functions in a particular module such
like in the default "prelude" module?
Typing :browse <Module> into GHCi will produce a list of all (exported) functions in a module with their type signatures. For the Prelude and other standard modules such as Data.List or Control.Monad, the names and type signatures should provide good insight into the functionality you can squeeze out of it. Second, you can browse the standard library and source on hackage.haskell.org. Third, GHCi on Acid (an extension to GHCi which you can cabal-install) gives you commands like :source and :doc, providing a direct link to the source code and documentation for a module; and :hoogle, which performs a Hoogle search on a given argument.
and how to find out how these
functions work in ghci environment
Try them out and study the source code. Since you can evaluate functions interactively in GHCi, you can get a feel for how functions behave; since you can read their source, you can get an exact definition of their behavior.
A nice starting point for this is Hoogle. http://haskell.org/hoogle/ Just type Prelude in the search box for example, it's a quite good resource with a lot of examples on using Haskell's features.