Commit 4a123f0f authored by Andrew Gibiansky's avatar Andrew Gibiansky

added demo notebook

parent 46797e1c
This diff is collapsed.
This diff is collapsed.
...@@ -69,7 +69,7 @@ typeCleaner = useStringType . foldl' (.) id (map (`replace` "") fullPrefixes) ...@@ -69,7 +69,7 @@ typeCleaner = useStringType . foldl' (.) id (map (`replace` "") fullPrefixes)
useStringType = replace "[Char]" "String" useStringType = replace "[Char]" "String"
write :: GhcMonad m => String -> m () write :: GhcMonad m => String -> m ()
write x = when debug $ liftIO $ hPutStrLn stderr x write x = when debug $ liftIO $ hPutStrLn stderr $ "DEBUG: " ++ x
type Interpreter = Ghc type Interpreter = Ghc
...@@ -466,8 +466,10 @@ evalCommand output (Expression expr) state = do ...@@ -466,8 +466,10 @@ evalCommand output (Expression expr) state = do
-- implement the Show typeclass. -- implement the Show typeclass.
isShowError errs = case find isPlain errs of isShowError errs = case find isPlain errs of
Just (Display PlainText msg) -> Just (Display PlainText msg) ->
startswith "No instance for (GHC.Show.Show" msg && -- Note that we rely on this error message being 'type cleaned', so
isInfixOf " arising from a use of `System.IO.print'" msg -- that `Show` is not displayed as GHC.Show.Show.
startswith "No instance for (Show" msg &&
isInfixOf " arising from a use of `print'" msg
Nothing -> False Nothing -> False
where isPlain (Display mime _) = mime == PlainText where isPlain (Display mime _) = mime == PlainText
...@@ -479,7 +481,9 @@ evalCommand output (Expression expr) state = do ...@@ -479,7 +481,9 @@ evalCommand output (Expression expr) state = do
-- attempting to do this without the serialization to binary and -- attempting to do this without the serialization to binary and
-- back gives very strange errors - all the types match but it -- back gives very strange errors - all the types match but it
-- refuses to decode back into a [DisplayData]. -- refuses to decode back into a [DisplayData].
runStmt displayExpr RunToCompletion -- Suppress output, so as not to mess up console.
capturedStatement (const $ return ()) displayExpr
displayedBytestring <- dynCompileExpr "IHaskell.Display.serializeDisplay it" displayedBytestring <- dynCompileExpr "IHaskell.Display.serializeDisplay it"
case fromDynamic displayedBytestring of case fromDynamic displayedBytestring of
Nothing -> error "Expecting lazy Bytestring" Nothing -> error "Expecting lazy Bytestring"
......
...@@ -80,10 +80,11 @@ htmlSuggestions suggests = table (concatMap toHtml suggests) ...@@ -80,10 +80,11 @@ htmlSuggestions suggests = table (concatMap toHtml suggests)
++ ++
row ( row (
el (style severityClass "Found:" ++ el (style severityClass "Found:" ++
style "code" (found suggest)) -- Things that look like this get highlighted.
styleId "highlight-code" "haskell" (found suggest))
++ ++
el (style severityClass "Why Not:" ++ el (style severityClass "Why Not:" ++
style "code" (whyNot suggest))) styleId "highlight-code" "haskell" (whyNot suggest)))
where where
severityClass = case severity suggest of severityClass = case severity suggest of
LintWarning -> "warning" LintWarning -> "warning"
...@@ -92,6 +93,9 @@ htmlSuggestions suggests = table (concatMap toHtml suggests) ...@@ -92,6 +93,9 @@ htmlSuggestions suggests = table (concatMap toHtml suggests)
style :: String -> String -> String style :: String -> String -> String
style cls thing = [i| <div class="suggestion-${cls}">${thing}</div> |] style cls thing = [i| <div class="suggestion-${cls}">${thing}</div> |]
styleId :: String -> String -> String -> String
styleId cls id thing = [i| <div class="${cls}" id="${id}">${thing}</div> |]
table :: String -> String table :: String -> String
table thing = [i| <table class="suggestion-table">${thing}</table> |] table thing = [i| <table class="suggestion-table">${thing}</table> |]
......
No preview for this file type
...@@ -81,22 +81,25 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){ ...@@ -81,22 +81,25 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){
IPython.CodeCell.options_default['cm_config']['mode'] = 'haskell'; IPython.CodeCell.options_default['cm_config']['mode'] = 'haskell';
}); });
var highlightHlint = function() { var highlightCodes = function() {
// Add logic here that should be run once per reply. // Add logic here that should be run once per reply.
$('.suggestion-code').each(function() { $('.highlight-code').each(function() {
var $this = $(this), var $this = $(this),
$code = $this.html(), $code = $this.html(),
$unescaped = $('<div/>').html($code).text(); $unescaped = $('<div/>').html($code).text();
$this.empty(); $this.empty();
// Never highlight this block again.
this.className = "";
CodeMirror(this, { CodeMirror(this, {
value: $unescaped, value: $unescaped,
mode: 'haskell', mode: this.id,
lineNumbers: false, lineNumbers: false,
readOnly: true readOnly: true
}); });
}); });
}; };
$([IPython.events]).on('shell_reply.Kernel', highlightHlint); $([IPython.events]).on('shell_reply.Kernel', highlightCodes);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment