-
Notifications
You must be signed in to change notification settings - Fork 144
Using Frege in Intellij IDEA
This page is for Java developers with prior exposure to Intellij IDEA.
For those who prefer working in an IDE, there is special Frege support for eclipse. However, Intellij IDEA can also be set up to compile and run Frege code smoothly even though the support is much less advanced. If you would like to see better Frege support in IDEA, please upvote the Frege issue.
This page describes how you can
- edit Frege code with basic syntax highlighting and general editing support (commenting, search/replace, hippy-completion)
- automatically compile Frege code whenever you change a .fr file
- run Frege code
- run QuickCheck
- start the Frege REPL internally with your code on the classpath.
Make sure you have a recent version of IntellijIDEA. Any 13.x version or higher should be fine. The free community edition is totally sufficient. Some basic knowledge of this IDE is assumed below.
Make sure you have a Java 1.7 SDK installed.
Install the following plugins from the JetBrains plugin site if you don't have them yet:
- the Haskell plugin
- the File Watcher plugin
Register Frege files as having the Haskell file type such that the Haskell plugin will do the syntax highlighting. Go to Preferences -> Editor -> File Types and add *.fr to the list of Haskell file extensions.
Next you need the Frege jar (and the REPL jars if you want to use it) as a library in IDEA. I recommend to create a "global" library such that you can share it between many projects. Note that you can point directly to your download locations of the jars, but you can also use IDEA's maven support to create libraries from maven (just select "maven", type "frege" when asked, and select your version of choice).
Here is the naming that I have chosen:
Head over to https://github.com/Dierk/HelloFrege and download the project. (You can use your preferred method of either cloning, forking, or downloading as zip).
You should now be able to open that project in IDEA. Most likely some of your local names are different from what the project expects, e.g. the name of the Java SDK and the names of the Frege and FregeRepl libraries. You need to adapt this in the project structure / module settings.
That being done, you can edit the Frege code with automatic compile, run all quickcheck tests and work with the REPL.
Rename the application, adapt the git settings, and add off you go with your own project!
We are working from two different modules:
- the source module is holding the actual Frege code
- the target module holds the *.class and *.java Files that Frege creates.
A file watcher is set on the source module to kick off the Frege compiler whenever it recognizes a change.
Running code, running tests, and starting the REPL is all done on the classpath of the target module.
When your Frege code has a main function (like HelloFrege.fr does) then after compiling a startable Java class appears under target/frege that you can start in the normal IDEA way (right-clicking and selecting "Run" or creating a Run Configuration). When using a Run Configuration you best remove the "Make before Run" option.
When selecting QuickCheck All from the Run Configuration, this will test all code under target/frege. You can limit the scope by applying more restrictive arguments (see the QuickCheck docs for details).
Selecting the REPL from the Run Configuration will start it on the target module but it first does a cd into the source directory such that you can load additional Frege files into the REPL at runtime if you want.
Very useful commands in the REPL are "browse " to see the types inside a Frege module or "help " to jump directly to the documentation.
I usually find myself in one the following modes:
- I have a startable module. In this case I have a Run Configuration for that I can start after any successful recompile with a keyboard shortcut.
- I work through tests only. In that case my shortcut starts the QuickCheck Run Configuration.
Make sure you have UTF-8 as your encoding!
Make sure you have Tabs-to-spaces set for your editor!
The file watcher sometimes needs some extra motivation to pick up a change and start the the compiler. Just add a space after some line and wait for half a second or so.
Some code suggestions by the Haskell plugin do not apply to Frege, e.g. True vs true.
The Haskell support for commenting lines or blocks also works fine for Frege (Cmd-/).
You can use "Hippi-Completion"! This feature is much more useful than one might think. After having started to write an identifier, hit Ctrl-Space and IDEA will try to find a token with the same beginning in the file and offer completions.
All the typical text-editing goodies are available. I've since recently come the love the Ctrl-G to select many occurrences of the same word and change all occurrences at once.
It is helpful to have the Frege project itself opened in a separate IDEA window - just for being able to search via Ctrl-Shift-F for module and function names in the prelude or in the examples.
It goes without saying that you can add additional Java modules to that project and let them call into the Frege code (i.e. the generated Java classes in the target module).
Have a lot of fun using Frege in IntelljIDEA!
Home
News
Community
- Online Communities
- Frege Ecosystem
- Frege Day 2015
- Protocol
- Simon Peyton-Jones Transcript
- Talks
- Articles
- Books
- Courses
Documentation
- Getting Started
- Online REPL
- FAQ
- Language and API Reference
- Libraries
- Language Interoperability
- Calling Frege From Java (old)
- Calling Java From Frege
- Calling Frege From Java (new)
- Compiler Manpage
- Source Code Doc
- Contributing
- System Properties
- License
- IDE Support
- Eclipse
- Intellij
- VS Code and Language Server
- Haskell
- Differences
- GHC Options vs Frege
- Learn You A Haskell Adaptations
- Official Doc
Downloads