


{-|
This is a description starting with a missing blank between {- and |
(that needs a matching -} for proper nesting).

More than two blank lines (above and below) will be stripped off.

You should also leave a blank or newline before closing your comment.-}



module Examples where

import Data.Char

import Data.List( )              -- treated like applications
import Data.Maybe (Maybe ( .. )) -- treated like infix symbol

numbers :: [Int]
numbers = [ 1 .. ] -- space ok before "]" (no section)

-- This line will be too long. The corresponding message is created independently from the scanner and therefore applies to code lines and comment lines orlines inside nested comments.

-- | bad characters are all non-ascii and non-printable characters
badChars :: String -> String
badChars = filter (\ c -> not $ isAscii c && isPrint c)


-- example for bad chars
tabBeforeString :: String
tabBeforeString =
	" "

(\\) :: Eq a => [a] -> [a] -> [a]
(\\) = error
  "just defined to show the final backslash of an infix declaration"

infix 5 \\

-- example for final backslash
multiLineString :: String
multiLineString = "We check for trailing backslashes because this may \
  \confuse the C preprocessor\n\
  \cpp, although cpphs will properly handle those.\n\n\
  \This also complains about multiline like this one."

multiLineString2 :: String
multiLineString2 = unlines
  [ "I think it is better to supply several lines of a text in this way"
  , "rather than using a multiline string."
  , ""
  , "Note, however, that the unlines result will have a final newline." ]

{-
My emacs mode removes trailing white spaces automatically,
therefore I cannot demonstrate this feature.
-}

operatorAsPrefix :: Int -> Int -> Int
operatorAsPrefix = ( + )

noSpaceNeededBefore :: Int -> Int
noSpaceNeededBefore = (1 + )

noSpaceNeededAfter :: Int -> Int
noSpaceNeededAfter = ( + 1)

noSpaceNeededBetween :: ([a], ())
noSpaceNeededBetween = ([ ], ( ))

multipleBlanks :: Char
multipleBlanks =  ' '    -- but ok before comment

breakLineAfterOf :: [a] -> [a]
breakLineAfterOf l = case l of [] -> []
                               ~(x : _) -> [x] -- the "~" needs no space

breakLineAfterdo :: Maybe [a] -> Maybe ([a], [a])
breakLineAfterdo m = do x <- m
                        y@(_ : _) <- m  -- the "@" needs no space
                        return (x, y)

semicolon :: Maybe a -> Maybe (a, a)
semicolon m = do { x <- m; y <- m; return (x, y) }

unaryMinus :: Int
unaryMinus = -1           -- ok with or without space

binaryMinus :: Int
binaryMinus = 3-1

data D = D { d :: !Int }  -- the "!" needs no space here


otherBinary :: Int
otherBinary = 1+2

spacesBetweenArguments :: (Int -> Int) -> Int -> Int
spacesBetweenArguments f x = f(x + 1)

spaceAfterLambda :: (((Int -> Int) -> Int) -> Int) -> Int
spaceAfterLambda f = f (\x -> x 1)
-- there may be a space before the lambda

possibleSplice :: (Char -> a) -> Char -> a
possibleSplice f y = f $(y :: Char)

-- list comprehensions, with e,d,p,t clashing with TH
possibleThQuote :: String
possibleThQuote = [e| e <- "abc"]

plainListComprehensions :: String
plainListComprehensions = [a| a <- "abc"]

{-
Some comments
here
-}
--
{- -}

-- missing final newline