File: indent.hs

package info (click to toggle)
haskell-mode 2.7.0-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 504 kB
  • ctags: 395
  • sloc: lisp: 5,431; haskell: 134; sh: 32; makefile: 2
file content (170 lines) | stat: -rw-r--r-- 5,120 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
-------------------------------------------------------------------------
-- Comments with allcaps `FIXME' indicate places where the indentation --
-- fails to find the correct indentation, whereas comments with        --
-- lowercase `fixme' indicate places where impossible indentations     --
-- are uselessly proposed.                                             --
-------------------------------------------------------------------------

-- | Fill-paragraph should avoid inserting an | on the following lines.

  -- | However, indented comments should still be indented. For great justice.

-- * Foo bar bazFoo bar bazFoo bar bazFoo bar bazFoo bar bazFoo bar baz

{- Here's
a more complex comment. Of doom. There is, indeed, great doom here. #-}

-- And a
-- multi-line
-- comment

-- compute the list of binary digits corresponding to an integer
-- Note: the least significant bit is the first element of the list
bdigits               :: Int -> [Int]   -- | commented to oblivion and back and forth and so forth
bdigits 0             = [0]
bdigits 1             = [1]
bdigits n | n>1       = n `mod` 2 :
                        bdigits (n `div` 2)
          | otherwise = error "bdigits of a negative number"

--  compute the value of an integer given its list of binary digits
--  Note: the least significant bit is the first element of the list
bvalue :: [Int]->Int
bvalue [] = error "bvalue of []"
bvalue s  = bval 1 s
    where
      bval e [] = 0
      bval e [] = 0             -- fixme: can't align with `where'.
      bval e (b:bs) | b==0 || b=="dd of " = b*e + bval (2*e) bs
                    | otherwise    = error "ill digit" -- Spurious 3rd step.
                                     foo

-- fixme: tab on the line above should insert `bvalue' at some point.

{- text
   indentation
   inside comments
 -}
toto a = ( hello
         , there                -- indentation of leading , and ;
         -- indentation of this comment.
         , my friends )

lili x = do let ofs x = 1
            print x

titi b =
    let                         -- fixme: can't indent at column 0
        x = let toto = 1
                tata = 2        -- fixme: can't indent lower than `toto'.
            in
                toto in
    do expr1
       {- text
        - indentation
        - inside comments
        -}
       let foo s  = let fro = 1
                        fri = 2   -- fixme: can't indent lower than `fro'.
                    in
                        hello
           foo2 = bar2  -- fixme: can't align with arg `s' in foo.
           foo1 = bar2  -- fixme: Can't be column 0.
       expr2

tata c =
    let bar = case foo          -- fixme: can't be col 0.
              of 1 -> blabla
                 2 -> blibli    -- fixme: only one possible indentation here.
        bar = case foo of
                _ -> blabla
        bar' = case foo
               of _ -> blabla
                  toto -> plulu
    
turlu d = if test
          then
              ifturl
          else
              adfaf

turlu d = if test then
              ifturl
          else
              sg

turly fg = toto
    where
      hello = 2
           

-- test from John Goerzen

x myVariableThing = case myVariablething of
                      Just z -> z
                      Nothing -> 0 -- fixme: "spurious" additional indents.

foo = let x = 1 in toto
                       titi     -- FIXME

foo = let foo x y = toto
              where
                toto = 2

instance Show Toto where
    foo x 4 = 50
         
data Toto = Foo
          | Bar
          deriving (Show)     -- FIXME

foo = let toto x = do let bar = 2
                      return 1
      in 3

 eval env (Llambda x e) =    -- FIXME: sole indentation is self???
     Vfun (\v -> eval (\y -> if (x == y) then v else env y) -- FIXME
                      e) -- FIXME

foo = case findprop attr props of
        Just x -> x

data T = T { granularity :: (Int, Int, Int, Int) -- FIXME: self indentation?
           , items :: Map (Int, Int, Int, Int) [Item] }

foo = case foo of
        [] ->
            case bar of
              [] ->
                  return ()
              (x:xs) -> -- FIXME

bar = do toto
         if titi
           then tutu            -- FIXME
           else tata            -- FIXME

insert :: Ord a => a -> b -> TreeMap a b -> TreeMap a b
insert x v Empty = Node 0 x v Empty Empty
insert x v (Node d x' v' t1 t2)
    | x == x'   = Node d x v t1 t2
    | x < x'    = Node ? x' v' (insert x v t1 Empty) t2
    |                           -- FIXME: wrong indent *if at EOB*


tinsertb x v (Node x' v' d1 t1 d2 t2)
    | x == x'   = (1 + max d1 d2,  Node x v d1 t1 d2 t2)
    | x < x' =
        case () of
          _ | d1' <= d2 + 1 => (1 + max d1' d2, Node x' v' d1' t1' d2 t2)
  -- d1' == d2 + 2: Need to rotate to rebalance.    FIXME CRASH
        else let (Node x'' v'' d1'' t1'' d2'' t2'') = t1'

test = if True then
           toto
       else if False then
           tata                 -- FIXME
       else                     -- FIXME
           titi

-- arch-tag: de0069e3-c0a0-495c-b441-d4ff6e0509b1