on master help sign in
Merge branch 'master' of github.com:edwinb/Idris-dev
commitb2f8c4c8c5103c28998b9f45b3f4ff84b21c6b6d authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 20 Oct 2012, 12:56 (14 years ago) parent49259a51865526
5 files changed+122−61
contribs/tool-support/vim/indent/idris.vim+76−59 lib/base.ipkg+3−2 lib/control/arrow.idr+21 lib/control/category.idr+15 lib/prelude/morphisms.idr+7
contribs/tool-support/vim/indent/idris.vim+76−59
@@ -3,7 +3,7 @@
33" Based on haskell indentation by motemen <motemen@gmail.com>
44"
55" author: raichoo (raichoo@googlemail.com)
6−" date: Sep 21 2012
6+" date: Oct 19 2012
77"
88" Modify g:idris_indent_if and g:idris_indent_case to
99" change indentation for `if'(default 3) and `case'(default 5).
@@ -11,92 +11,109 @@
1111" > let g:idris_indent_if = 2
1212
1313if exists('b:did_indent')
14− finish
14+ finish
1515endif
1616
1717let b:did_indent = 1
1818
1919if !exists('g:idris_indent_if')
20− " if bool
21− " >>>then ...
22− " >>>else ...
23− let g:idris_indent_if = 3
20+ " if bool
21+ " >>>then ...
22+ " >>>else ...
23+ let g:idris_indent_if = 3
2424endif
2525
2626if !exists('g:idris_indent_case')
27− " case xs of
28− " >>>>>[] -> ...
29− " >>>>>(y:ys) -> ...
30− let g:idris_indent_case = 5
27+ " case xs of
28+ " >>>>>[] -> ...
29+ " >>>>>(y::ys) -> ...
30+ let g:idris_indent_case = 5
31+endif
32+
33+if !exists('g:idris_indent_let')
34+ " let x : Nat = O in
35+ " >>>>x
36+ let g:idris_indent_let = 4
37+endif
38+
39+if !exists('g:idris_indent_where')
40+ " where f : Nat -> Nat
41+ " >>>>>>f x = x
42+ let g:idris_indent_where = 6
43+endif
44+
45+if !exists('g:idris_indent_do')
46+ " do x <- a
47+ " >>>y <- b
48+ let g:idris_indent_do = 3
3149endif
3250
3351setlocal indentexpr=GetIdrisIndent()
3452setlocal indentkeys=!^F,o,O
3553
3654function! GetIdrisIndent()
37− let line = substitute(getline(getpos('.')[1] - 1), '\t', repeat(' ', &tabstop), 'g')
55+ let prevline = getline(v:lnum - 1)
3856
39− if line =~ '[!#$%&*+./<=>?@\\^|~-]$\|\<do$'
40− return match(line, '\s*where \zs\|\S') + &shiftwidth
57+ if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
58+ let s = match(prevline, '[:=]')
59+ if s > 0
60+ return s + 2
61+ else
62+ return match(prevline, '\S')
4163 endif
64+ endif
4265
43− if line =~ '{$'
44− return match(line, '\s*where \zs\|\S') + &shiftwidth
45− endif
66+ if prevline =~ '[{([]\s*$'
67+ return match(prevline, '[{([]')
68+ endif
4669
47− if line =~ '^\s*\(data\|instance\|class\).*\&.*where$'
48− return match(line, '\(data\|instance\|class\)') + &shiftwidth
49− endif
70+ if prevline =~ 'let\s\+.\+in\s*$'
71+ return match(prevline, 'let') + g:idris_indent_let
72+ endif
5073
51− if line =~ '^\s*using\s*(.\+)$'
52− return match(line, 'using') + &shiftwidth
74+ if prevline !~ '\<else\>'
75+ let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
76+ if s > 0
77+ return s
5378 endif
5479
55− if line =~ '\<with\>'
56− return &shiftwidth
80+ let s = match(prevline, '\<if\>')
81+ if s > 0
82+ return s + g:idris_indent_if
5783 endif
84+ endif
5885
59− if line =~ '^\s*data\s\+\S*\s\+=\s\+\S\+$'
60− return match(line, '=')
61− endif
86+ if prevline =~ '\(where\|do\|=\)\s*$'
87+ return match(prevline, '\S') + &shiftwidth
88+ endif
6289
63− if line =~ '^\s*namespace\s\+\S\+$'
64− return match(line, 'namespace') + &shiftwidth
65− endif
90+ if prevline =~ 'where\s\+\S\+.*$'
91+ return match(prevline, 'where') + g:idris_indent_where
92+ endif
6693
67− if line =~ ')$'
68− let pos = getpos('.')
69− normal k$
70− let paren_end = getpos('.')
71− normal %
72− let paren_begin = getpos('.')
73− call setpos('.', pos)
74− if paren_begin[1] != paren_end[1]
75− return paren_begin[2] - 1
76− endif
77− endif
94+ if prevline =~ 'do\s\+\S\+.*$'
95+ return match(prevline, 'do') + g:idris_indent_do
96+ endif
7897
79− if line !~ '\<else\>'
80− let s = match(line, '\<if\>.*\&.*\zs\<then\>')
81− if s > 0
82− return s
83− endif
98+ if prevline =~ '^\s*data\s\+[^=]\+\s\+=\s\+\S\+.*$'
99+ return match(prevline, '=')
100+ endif
84101
85− let s = match(line, '\<if\>')
86− if s > 0
87− return s + g:idris_indent_if
88− endif
89− endif
102+ if prevline =~ 'with\s\+([^)]*)\s*$'
103+ return match(prevline, '\S') + &shiftwidth
104+ endif
90105
91− let s = match(line, '\<do\s\+\zs[^{]\|\<where\s\+\zs\w\|\<let\s\+\zs\S\|^\s*\zs|\s')
92− if s > 0
93− return s
94− endif
106+ if prevline =~ 'case\s\+.\+of\s*$'
107+ return match(prevline, 'case') + g:idris_indent_case
108+ endif
95109
96− let s = match(line, '\<case\>')
97− if s > 0
98− return s + g:idris_indent_case
99− endif
110+ if prevline =~ '^\s*\(namespace\|data\)\s\+\S\+\s*$'
111+ return match(prevline, '\(namespace\|data\)') + &shiftwidth
112+ endif
113+
114+ if prevline =~ '^\s*using\s\+([^(]*)\s*$'
115+ return match(prevline, 'using') + &shiftwidth
116+ endif
100117
101− return match(line, '\S')
118+ return match(prevline, '\S')
102119endfunction
lib/base.ipkg+3−2
@@ -6,10 +6,11 @@ modules = builtins, prelude, io, system,
66 prelude.algebra, prelude.cast, prelude.nat, prelude.fin,
77 prelude.list, prelude.maybe, prelude.monad, prelude.applicative,
88 prelude.either, prelude.vect, prelude.strings, prelude.char,
9− prelude.heap, prelude.complex,
9+ prelude.heap, prelude.complex, prelude.morphisms,
1010
1111 network.cgi,
1212
1313 language.reflection,
1414
15− control.monad.identity, control.monad.state
15+ control.monad.identity, control.monad.state, control.category,
16+ control.arrow
lib/control/arrow.idrnew file+21
@@ -0,0 +1,21 @@
1+module category.arrow
2+
3+import prelude.morphisms
4+import control.category
5+
6+infixr 3 ***
7+infixr 3 &&&
8+
9+class Category arr => Arrow (arr : Set -> Set -> Set) where
10+ arrow : (a -> b) -> arr a b
11+ first : arr a b -> arr (a, c) (b, c)
12+ second : arr a b -> arr (c, a) (c, b)
13+ (***) : arr a b -> arr a' b' -> arr (a, a') (b, b')
14+ (&&&) : arr a b -> arr a b' -> arr a (b, b')
15+
16+instance Arrow Morphism where
17+ arrow f = Homo f
18+ first (Homo f) = Homo $ \(a, b) => (f a, b)
19+ second (Homo f) = Homo $ \(a, b) => (a, f b)
20+ (Homo f) *** (Homo g) = Homo $ \(a, b) => (f a, g b)
21+ (Homo f) &&& (Homo g) = Homo $ \a => (f a, g a)
lib/control/category.idrnew file+15
@@ -0,0 +1,15 @@
1+module control.category
2+
3+import prelude.morphisms
4+
5+class Category (cat : Set -> Set -> Set) where
6+ id : cat a a
7+ (.) : cat b c -> cat a b -> cat a c
8+
9+instance Category Morphism where
10+ id = Homo builtins.id
11+ (Homo f) . (Homo g) = Homo $ builtins.(.) f g
12+
13+infixr 1 >>>
14+(>>>) : Category cat => cat a b -> cat b c -> cat a c
15+f >>> g = g . f
lib/prelude/morphisms.idrnew file+7
@@ -0,0 +1,7 @@
1+module prelude.morphisms
2+
3+data Morphism : Set -> Set -> Set where
4+ Homo : (a -> b) -> Morphism a b
5+
6+($) : Morphism a b -> a -> b
7+(Homo f) $ a = f a