Skip to content

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.

Working with JSON

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 }
Clone this wiki locally