In [1]:
-- First of all, we can evaluate simple expressions.
3 + 5
"Hello, " ++ "World!"
In [2]:
it1
In [3]:
-- Unlike in GHCi, we can have multi-line expressions.
concat [
"Hello",
", ",
"World!"
] :: String
In [4]:
thing :: String -> Int -> Int
thing "no" _ = 100
thing str int = int + length str
thing "no" 10
thing "ah" 10
In [5]:
print "What's going on?"
In [6]:
-- We can disable extensions.
:ext NoEmptyDataDecls
data Thing
In [7]:
-- And enable extensions.
:ext EmptyDataDecls
data Thing
In [8]:
-- Various data declarations work fine.
data One
= A String
| B Int
deriving Show
print [A "Hello", B 10]
In [9]:
-- We can look at types like in GHCi.
:ty 3 + 3
In [10]:
:opt no-pager
In [11]:
-- What is the Integral typeclass?
:info Integral
In [12]:
import IHaskell.Display
data Color = Red | Green | Blue
instance IHaskellDisplay Color where
display color = return $ Display [html code]
where
code = concat ["<div style='font-weight: bold; color:"
, css color
, "'>Look!</div>"]
css Red = "red"
css Blue = "blue"
css Green = "green"
Red
Green
Blue
In [13]:
-- There is also hlint integration enabled by default.
-- If you write sketchy code, it will tell you:
f :: Int -> Int
f x = x + 1
-- Most warnings are orange...
f $ 3
do
return 3
In [14]:
:help
In [15]:
x = ['a'..'z']
x !! 3
:sprint x
In [16]:
-- If your code isn't running fast enough, you can just put it into a module.
module A.B where
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
In [17]:
-- The module is automatically imported unqualified.
print $ A.B.fib 20
print $ fib 20
In [18]:
f 3
In [19]:
import qualified A.B as Fib
Fib.fib 20
fib 20