Commit 7c8ffd3d authored by thomie's avatar thomie

GHCi docs: layout rule is respected inside :{ :}

Summary:
I don't know if or when this changed, but the documentation on :{ :}
(multiline input) seems out of date. Layout rule works fine. I added a
regression test.

Reviewers: austin

Subscribers: thomie, bgamari

Differential Revision: https://phabricator.haskell.org/D1013
parent 111ba4be
...@@ -437,10 +437,10 @@ Prelude> ...@@ -437,10 +437,10 @@ Prelude>
<listitem> <listitem>
<para>The variable's type is not polymorphic, is not <para>The variable's type is not polymorphic, is not
<literal>()</literal>, and is an instance of <literal>()</literal>, and is an instance of
<literal>Show</literal></para> <literal>Show</literal>.</para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<indexterm><primary><option>-fprint-bind-result</option></primary></indexterm><indexterm><primary><option>-fno-print-bind-result</option></primary></indexterm>. <indexterm><primary><option>-fprint-bind-result</option></primary></indexterm><indexterm><primary><option>-fno-print-bind-result</option></primary></indexterm>
</para> </para>
<para>Of course, you can also bind normal non-IO expressions <para>Of course, you can also bind normal non-IO expressions
...@@ -477,9 +477,9 @@ Prelude> ...@@ -477,9 +477,9 @@ Prelude>
<para>However, this quickly gets tedious when defining functions <para>However, this quickly gets tedious when defining functions
with multiple clauses, or groups of mutually recursive functions, with multiple clauses, or groups of mutually recursive functions,
because the complete definition has to be given on a single line, because the complete definition has to be given on a single line,
using explicit braces and semicolons instead of layout:</para> using explicit semicolons instead of layout:</para>
<screen> <screen>
Prelude> let { f op n [] = n ; f op n (h:t) = h `op` f op n t } Prelude> let f op n [] = n ; f op n (h:t) = h `op` f op n t
Prelude> f (+) 0 [1..3] Prelude> f (+) 0 [1..3]
6 6
Prelude> Prelude>
...@@ -489,18 +489,14 @@ Prelude> ...@@ -489,18 +489,14 @@ Prelude>
<literal>:}</literal> (each on a single line of its own):</para> <literal>:}</literal> (each on a single line of its own):</para>
<screen> <screen>
Prelude> :{ Prelude> :{
Prelude| let { g op n [] = n Prelude| let g op n [] = n
Prelude| ; g op n (h:t) = h `op` g op n t Prelude| g op n (h:t) = h `op` g op n t
Prelude| }
Prelude| :} Prelude| :}
Prelude> g (*) 1 [1..3] Prelude> g (*) 1 [1..3]
6 6
</screen> </screen>
<para>Such multiline commands can be used with any GHCi command, <para>Such multiline commands can be used with any GHCi command,
and the lines between <literal>:{</literal> and and note that the layout rule is in effect.
<literal>:}</literal> are simply merged into a single line for
interpretation. That implies that each such group must form a single
valid command when merged, and that no layout rule is used.
The main purpose of multiline commands is not to replace module The main purpose of multiline commands is not to replace module
loading but to make definitions in .ghci-files (see <xref loading but to make definitions in .ghci-files (see <xref
linkend="ghci-dot-files"/>) more readable and maintainable.</para> linkend="ghci-dot-files"/>) more readable and maintainable.</para>
...@@ -575,7 +571,7 @@ Prelude> ...@@ -575,7 +571,7 @@ Prelude>
</screen> </screen>
<para>Explicit braces and semicolons can be used instead of <para>Explicit braces and semicolons can be used instead of
layout, as usual:</para> layout:</para>
<screen> <screen>
Prelude> do { Prelude> do {
......
...@@ -9,6 +9,17 @@ putStrLn "-- via stdin" ...@@ -9,6 +9,17 @@ putStrLn "-- via stdin"
} }
:} :}
print (f 0,f 1,y) print (f 0,f 1,y)
putStrLn "-- layout rule instead of explicit braces and semicolons works too"
:{
let
g 0 = 1
g 1 = w
where w = 2
z = 3
:}
print (g 0,g 1,z)
:{ :{
:browse :browse
Data.Maybe Data.Maybe
......
-- testing ghci multiline commands :{ .. :} -- testing ghci multiline commands :{ .. :}
-- via stdin -- via stdin
(1,2,3) (1,2,3)
catMaybes :: [Maybe a] -> [a] -- layout rule instead of explicit braces and semicolons works too
fromJust :: Maybe a -> a (1,2,3)
fromMaybe :: a -> Maybe a -> a catMaybes :: [Maybe a] -> [a]
isJust :: Maybe a -> Bool fromJust :: Maybe a -> a
isNothing :: Maybe a -> Bool fromMaybe :: a -> Maybe a -> a
listToMaybe :: [a] -> Maybe a isJust :: Maybe a -> Bool
mapMaybe :: (a -> Maybe b) -> [a] -> [b] isNothing :: Maybe a -> Bool
maybe :: b -> (a -> b) -> Maybe a -> b listToMaybe :: [a] -> Maybe a
maybeToList :: Maybe a -> [a] mapMaybe :: (a -> Maybe b) -> [a] -> [b]
data Maybe a = Nothing | Just a maybe :: b -> (a -> b) -> Maybe a -> b
-- via readFile maybeToList :: Maybe a -> [a]
(True,False) data Maybe a = Nothing | Just a
id :: a -> a -- via readFile
(True,False)
id :: a -> a
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