How to tell if a haskell sourcecode has Bang - haskell

Is there any library function that tells if a given .hs file uses strictness annotation? Or do I have to go into the syntax tree?

Was able to figure this out with the parsers in Language.Haskell.Exts, which is from haskell-src-exts. Thanks luqui!

Related

How does one browse a module's functions and their types?

How do Haskell programmers browse through a module to see the available methods and data types?
I am asking because i think that there is a faster and easier way then to always enter hoogle and look them up (as i am currently doing). I just want to see the methods and signatures.
P.S I discovered GHCI provides a browse method but is there any way to pipe the result in a file ? Redirecting ghci output to file ?
How about a simple command line option and shell redirect?
ghci -e ':browse Prelude' > file.txt
My usual approach to this is finding the package on Hackage and browsing the docs on there - which have the methods and signatures (types).
For example for Data.List: http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-List.html

How to see code of Monad Reader?

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.

is there a command to apply hlint suggestions in emacs?

I'm using flycheck and haskell-hlint in emacs when I write Haskell codes
and I think it will be great if I can apply those hlint suggestions by invoking some emacs procedures instead of modifying the code manually.
If there isn't one available and in case I have to write this procedure for myself:
Is it guaranteed that hlint output is always of the following form:
Found:
{Text1}
Why not:
{Text2}
where {Text?} can always be parsed as a Haskell abstract syntax tree?
HLint comes with an Emacs script hs-lint.el that does the replacement you are after, details are in the README. The script isn't officially supported by the HLint developer, but some people have had some success with it.
Separately, there are plans to provide a proper replacement feature in HLint, which if provided would be easy to integrate with Emacs. While it's always been on the back-burner, there are now people working on the necessary whitespace-aware-syntax-replacement libraries that HLint requires.
There is an HLint Refactor Mode building on the apply-refact tool that provides HLint replacements in Emacs.

Full definition of .cabal file syntax

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.

How to use :? to find all function list and manual in ghci

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.

Resources