-
Notifications
You must be signed in to change notification settings - Fork 145
Online REPL Walkthrough
Dierk König edited this page May 29, 2020
·
12 revisions
In the online REPL, you can use the editor pane on the left hand side to insert and edit Frege code.
You can then run it by clicking the 'Evaluate' button at the bottom or by pressing 'Ctrl + Enter'.
This wiki page should provide you with some ideas that you may want to try in the Repl.
Please note that at the moment any printing to stdout does not lead to visible output. Only the value of the last evaluated expression is visible.
Copy the following code in the editor and evaluate it.
This will show the :load editor
command in the repl and some evaluation result.
You can now run the run function by typing run
in the repl.
module examples.JSONExample where
import Data.JSON
data Coordinate = Coordinate { lon :: Float, lat :: Float }
derive Show Coordinate
data Weather = Weather { loc :: Coordinate
, temp :: Int
, desc :: String
, alert :: Maybe String
}
derive Show Weather
instance ToJSON Coordinate where
toJSON coord = Struct [ ("lon", toJSON coord.lon), ("lat", toJSON coord.lat) ]
instance ToJSON Weather where
toJSON Weather{loc, temp, desc, alert}
= Struct [ ("loc", toJSON loc)
, ("temp", toJSON temp)
, ("desc", toJSON desc)
, ("alert", toJSON $ fromMaybe "null" alert)
]
run = toJSON $ Weather location 98 "overcast clouds" (Just "Excessive heat")
where
location = Coordinate { lon = -122.09, lat = 37.39 }
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