ihaskell-0.4.3.0: A Haskell backend kernel for the IPython project.

Safe HaskellNone

IHaskell.Display

Contents

Description

If you are interested in the IHaskell library for the purpose of augmenting the IHaskell notebook or writing your own display mechanisms and widgets, this module contains all functions you need.

In order to create a display mechanism for a particular data type, write a module named (for example) IHaskell.Display.YourThing in a package named ihaskell-yourThing. (Note the capitalization - it's important!) Then, in that module, add an instance of IHaskellDisplay for your data type. Similarly, to create a widget, add an instance of IHaskellWidget.

An example of creating a display is provided in the demo notebook.

Synopsis

Rich display and interactive display typeclasses and types

class IHaskellDisplay a whereSource

A class for displayable Haskell types.

IHaskell's displaying of results behaves as if these two overlapping/undecidable instances also existed:

 instance (Show a) => IHaskellDisplay a
 instance Show a where shows _ = id

Methods

display :: a -> IO DisplaySource

Instances

IHaskellDisplay DisplayData 
IHaskellDisplay Display 
IHaskellDisplay Widget 
IHaskellDisplay a => IHaskellDisplay [a] 
IHaskellDisplay a => IHaskellDisplay (IO a)

these instances cause the image, html etc. which look like:

 Display
 [Display]
 IO [Display]
 IO (IO Display)

be run the IO and get rendered (if the frontend allows it) in the pretty form.

data Display Source

Wrapper for ipython-kernel's DisplayData which allows sending multiple results from the same expression.

data DisplayData Source

Data for display: a string with associated MIME type.

Constructors

DisplayData MimeType Text 

class IHaskellDisplay a => IHaskellWidget a whereSource

Display as an interactive widget.

Methods

targetName :: a -> StringSource

Output target name for this widget. The actual input parameter should be ignored.

openSource

Arguments

:: a

Widget to open a comm port with.

-> (Value -> IO ())

Way to respond to the message.

-> IO () 

Called when the comm is opened. Allows additional messages to be sent after comm open.

commSource

Arguments

:: a

Widget which is being communicated with.

-> Value

Sent data.

-> (Value -> IO ())

Way to respond to the message.

-> IO () 

Respond to a comm data message.

closeSource

Arguments

:: a

Widget to close comm port with.

-> Value

Sent data.

-> IO () 

Close the comm, releasing any resources we might need to.

Interactive use functions

printDisplay :: IHaskellDisplay a => a -> IO ()Source

Write to the display channel. The contents will be displayed in the notebook once the current execution call ends.

Constructors for displays

plain :: String -> DisplayDataSource

Generate a plain text display.

html :: String -> DisplayDataSource

Generate an HTML display.

png :: Width -> Height -> Base64 -> DisplayDataSource

Generate a PNG display of the given width and height. Data must be provided in a Base64 encoded manner, suitable for embedding into HTML. The base64 function may be used to encode data into this format.

jpg :: Width -> Height -> Base64 -> DisplayDataSource

Generate a JPG display of the given width and height. Data must be provided in a Base64 encoded manner, suitable for embedding into HTML. The base64 function may be used to encode data into this format.

svg :: String -> DisplayDataSource

Generate an SVG display.

latex :: String -> DisplayDataSource

Generate a LaTeX display.

javascript :: String -> DisplayDataSource

Generate a Javascript display.

many :: [Display] -> DisplaySource

Encode many displays into a single one. All will be output.

Image and data encoding functions

type Width = IntSource

Possible MIME types for the display data.

encode64 :: String -> Base64Source

Convert from a string into base 64 encoded data.

base64 :: ByteString -> Base64Source

Convert from a ByteString into base 64 encoded data.

Utilities

switchToTmpDir :: IO ()Source

Convenience function for client libraries. Switch to a temporary directory so that any files we create aren't visible. On Unix, this is usually /tmp.

Internal only use

displayFromChan :: IO (Maybe Display)Source

Take everything that was put into the displayChan at that point out, and make a Display out of it.

serializeDisplay :: Display -> ByteStringSource

For internal use within IHaskell. Serialize displays to a ByteString.