Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
2bac9299
Commit
2bac9299
authored
Dec 12, 2006
by
Ian Lynagh
Browse files
Fix more warnings
parent
e550eefe
Changes
1
Hide whitespace changes
Inline
Sidebyside
utils/nofibanalyse/GenUtils.lhs
View file @
2bac9299
...
...
@@ 104,6 +104,7 @@ This will never terminate.
>
where
>
match
(
a
:
b
:
_
)

a
`
eq
`
b
=
a
>
match
(
_
:
c
)
=
match
c
>
match
[]
=
error
"GenUtils.mkClosure: Can't happen"
>
foldb
::
(
a
>
a
>
a
)
>
[
a
]
>
a
>
foldb
_
[]
=
error
"can't reduce an empty list using foldb"
...
...
@@ 161,9 +162,12 @@ quickest sorting function I know of.
Goferlike stuff:
>
fst3
(
a
,
_
,
_
)
=
a
>
snd3
(
_
,
a
,
_
)
=
a
>
thd3
(
_
,
_
,
a
)
=
a
>
fst3
::
(
a
,
b
,
c
)
>
a
>
fst3
(
a
,
_
,
_
)
=
a
>
snd3
::
(
a
,
b
,
c
)
>
b
>
snd3
(
_
,
a
,
_
)
=
a
>
thd3
::
(
a
,
b
,
c
)
>
c
>
thd3
(
_
,
_
,
a
)
=
a
>
cjustify
,
ljustify
,
rjustify
::
Int
>
String
>
String
>
cjustify
n
s
=
space
halfm
++
s
++
space
(
m

halfm
)
...
...
@@ 180,13 +184,14 @@ Goferlike stuff:
>
copy
n
x
=
take
n
xs
where
xs
=
x
:
xs
>
partition'
::
(
Eq
b
)
=>
(
a
>
b
)
>
[
a
]
>
[[
a
]]
>
partition'
f
[]
=
[]
>
partition'
f
[
x
]
=
[[
x
]]
>
partition'
_
[]
=
[]
>
partition'
_
[
x
]
=
[[
x
]]
>
partition'
f
(
x
:
x'
:
xs
)

f
x
==
f
x'
>
=
tack
x
(
partition'
f
(
x'
:
xs
))
>

otherwise
>
=
[
x
]
:
partition'
f
(
x'
:
xs
)
>
tack
::
a
>
[[
a
]]
>
[[
a
]]
>
tack
x
xss
=
(
x
:
head
xss
)
:
tail
xss
>
combinePairs
::
(
Ord
a
)
=>
[(
a
,
b
)]
>
[(
a
,[
b
])]
...
...
@@ 221,8 +226,7 @@ Goferlike stuff:
>
assocMaybeErr
::
(
Eq
a
)
=>
[(
a
,
b
)]
>
a
>
MaybeErr
b
String
>
assocMaybeErr
env
k
=
case
[
val

(
key
,
val
)
<
env
,
k
==
key
]
of
>
[]
>
Failed
"assoc: "
>
(
val
:
vs
)
>
Succeeded
val
>
>
(
val
:
_
)
>
Succeeded
val
Now some utilties involving arrays.
Here is a version of @elem@ that uses partual application
...
...
@@ 251,47 +255,3 @@ will give a very efficent variation of the fib function.
>
memoise
bds
f
=
(
!
)
arr
>
where
arr
=
array
bds
[
ASSOC
(
t
,
f
t
)

t
<
range
bds
]
>
mapAccumR
::
(
acc
>
x
>
(
acc
,
y
))
 Function of elt of input list
>
 and accumulator, returning new
>
 accumulator and elt of result list
>
>
acc
 Initial accumulator
>
>
[
x
]
 Input list
>
>
(
acc
,
[
y
])
 Final accumulator and result list
>
>
mapAccumR
f
b
[]
=
(
b
,
[]
)
>
mapAccumR
f
b
(
x
:
xs
)
=
(
b''
,
x'
:
xs'
)
where
>
(
b''
,
x'
)
=
f
b'
x
>
(
b'
,
xs'
)
=
mapAccumR
f
b
xs
>
mapAccumL
::
(
acc
>
x
>
(
acc
,
y
))
 Function of elt of input list
>
 and accumulator, returning new
>
 accumulator and elt of result list
>
>
acc
 Initial accumulator
>
>
[
x
]
 Input list
>
>
(
acc
,
[
y
])
 Final accumulator and result list
>
>
mapAccumL
f
b
[]
=
(
b
,
[]
)
>
mapAccumL
f
b
(
x
:
xs
)
=
(
b''
,
x'
:
xs'
)
where
>
(
b'
,
x'
)
=
f
b
x
>
(
b''
,
xs'
)
=
mapAccumL
f
b'
xs
Here is the bidirectional version ...
>
mapAccumB
::
(
accl
>
accr
>
x
>
(
accl
,
accr
,
y
))
>
 Function of elt of input list
>
 and accumulator, returning new
>
 accumulator and elt of result list
>
>
accl
 Initial accumulator from left
>
>
accr
 Initial accumulator from right
>
>
[
x
]
 Input list
>
>
(
accl
,
accr
,
[
y
])
 Final accumulator and result list
>
>
mapAccumB
f
a
b
[]
=
(
a
,
b
,
[]
)
>
mapAccumB
f
a
b
(
x
:
xs
)
=
(
a''
,
b''
,
y
:
ys
)
>
where
>
(
a'
,
b''
,
y
)
=
f
a
b'
x
>
(
a''
,
b'
,
ys
)
=
mapAccumB
f
a'
b
xs
>
assert
False
x
=
error
"assert Failed"
>
assert
True
x
=
x
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment