Commit 2b8fcbd1 authored by Gabor Greif's avatar Gabor Greif 💬

Typofixes and some whitespace corrections

parent b760674c
Pipeline #1402 passed with stage
in 5 minutes and 1 second
......@@ -329,7 +329,7 @@ happyMonadReduce to get polymorphic recursion. Sigh.
> else str "(HappyTerminal "
> . mkHappyTerminalVar n t
> . char ')'
>
>
> tokLets code
> | coerce && not (null cases)
> = interleave "\n\t" cases
......@@ -394,7 +394,7 @@ The token conversion function.
> . str " sts stk"
> eofError = str " (error \"reading EOF!\")"
> eofTok = showInt (tokIndex eof)
>
>
> doAction = case target of
> TargetArrayBased -> str "happyDoAction i tk action"
> _ -> str "action i i tk (HappyState action)"
......@@ -478,7 +478,7 @@ machinery to discard states in the parser...
> produceActionTable TargetHaskell
> = foldr (.) id (map (produceStateFunction goto) (assocs action))
>
>
> produceActionTable TargetArrayBased
> = produceActionArray
> . produceReduceArray
......@@ -496,7 +496,7 @@ machinery to discard states in the parser...
> . str "\n\n"
>
> where gotos = goto ! state
>
>
> produceActions (t, LR'Fail{-'-}) = id
> produceActions (t, action@(LR'Reduce{-'-} _ _))
> | action == default_act = id
......@@ -505,17 +505,17 @@ machinery to discard states in the parser...
> produceActions (t, action)
> = actionFunction t
> . mkAction action . str "\n"
>
>
> produceGotos (t, Goto i)
> = actionFunction t
> . str "happyGoto " . mkActionName i . str "\n"
> produceGotos (t, NoGoto) = id
>
>
> actionFunction t
> = mkActionName state . strspace
> . ('(' :) . showInt t
> . str ") = "
>
>
> default_act = getDefault assocs_acts
>
> assocs_acts = assocs acts
......@@ -528,7 +528,7 @@ action array indexed by (terminal * last_state) + state
> . str "happyActOffsets = HappyA# \"" --"
> . str (hexChars act_offs)
> . str "\"#\n\n" --"
>
>
> . str "happyGotoOffsets :: HappyAddr\n"
> . str "happyGotoOffsets = HappyA# \"" --"
> . str (hexChars goto_offs)
......@@ -538,12 +538,12 @@ action array indexed by (terminal * last_state) + state
> . str "happyDefActions = HappyA# \"" --"
> . str (hexChars defaults)
> . str "\"#\n\n" --"
>
>
> . str "happyCheck :: HappyAddr\n"
> . str "happyCheck = HappyA# \"" --"
> . str (hexChars check)
> . str "\"#\n\n" --"
>
>
> . str "happyTable :: HappyAddr\n"
> . str "happyTable = HappyA# \"" --"
> . str (hexChars table)
......@@ -555,31 +555,31 @@ action array indexed by (terminal * last_state) + state
> . shows (n_states) . str ") (["
> . interleave' "," (map shows act_offs)
> . str "\n\t])\n\n"
>
>
> . str "happyGotoOffsets :: Array Int Int\n"
> . str "happyGotoOffsets = listArray (0,"
> . shows (n_states) . str ") (["
> . interleave' "," (map shows goto_offs)
> . str "\n\t])\n\n"
>
>
> . str "happyDefActions :: Array Int Int\n"
> . str "happyDefActions = listArray (0,"
> . shows (n_states) . str ") (["
> . interleave' "," (map shows defaults)
> . str "\n\t])\n\n"
>
>
> . str "happyCheck :: Array Int Int\n"
> . str "happyCheck = listArray (0,"
> . shows table_size . str ") (["
> . interleave' "," (map shows check)
> . str "\n\t])\n\n"
>
>
> . str "happyTable :: Array Int Int\n"
> . str "happyTable = listArray (0,"
> . shows table_size . str ") (["
> . interleave' "," (map shows table)
> . str "\n\t])\n\n"
>
>
> (_, last_state) = bounds action
> n_states = last_state + 1
> n_terminals = length terms
......@@ -614,7 +614,7 @@ This lets examples like:
| HappyAbsSyn2 ( HaskExp )
| HappyAbsSyn3 t1
*share* the defintion for ( HaskExp )
*share* the definition for ( HaskExp )
data HappyAbsSyn t1
= HappyTerminal ( HaskToken )
......@@ -623,7 +623,7 @@ This lets examples like:
... cuting down on the work that the type checker has to do.
Note, this *could* introduce lack of polymophism,
Note, this *could* introduce lack of polymorphism,
for types that have alphas in them. Maybe we should
outlaw them inside { }
......@@ -748,7 +748,7 @@ compatibility) is not passed the current token.
> TargetHaskell -> str "action_" . shows no
> TargetArrayBased
> | ghc -> shows no . str "#"
> | otherwise -> shows no
> | otherwise -> shows no
> . maybe_tks
> . str ") "
> . brack' (if coerce
......@@ -937,7 +937,7 @@ See notes under "Action Tables" above for some subtleties in this function.
>
> (table,check,act_offs,goto_offs,max_off)
> = runST (genTables (length actions) max_token sorted_actions)
>
>
> -- the maximum token number used in the parser
> max_token = max n_terminals (n_starts+n_nonterminals) - 1
>
......
......@@ -14,7 +14,7 @@ Naive functional version. Generates a list of tuples + explodes by
scanning the list. Query is hand-translated into recursive functions
This version uses parallel Strategies. The intention is to very
clearly seperate computation from evaluation.
clearly separate computation from evaluation.
Good gransim arguments: 70 90 100
Good GUM arguments: 900 980 1000
......
......@@ -12,7 +12,7 @@ scanning the list.
Version II
This version uses parallel Strategies, of type a -> a. The intention
is to very clearly seperate computation from evaluation.
is to very clearly separate computation from evaluation.
Good granprof arguments: 80 90 100
......
......@@ -10,7 +10,7 @@ Naive functional version. Generates a list of tuples + explodes by
scanning the list. Query is hand-translated into recursive functions
This version uses parallel Strategies. The intention is to very
clearly seperate computation from evaluation.
clearly separate computation from evaluation.
-}
......
......@@ -16,8 +16,8 @@ type Transaction = Dbt -> (Msgt,Dbt)
{-
The following is the type definition of the history recorcd (Histrt) as defined in
the DebitCredit benchmark. The last entity in the history record should be a time
The following is the type definition of the history record (Histrt) as defined in
the DebitCredit benchmark. The last entity in the history record should be a time
stamp, but the current implementation simply sets the time stamp to the dummy value 0.
-}
......@@ -35,7 +35,7 @@ data Histrt = His Int Int Int Int Int
records in this tree tend to be hot spots and using a big tree (many
non-leaf nodes) will increase the efficiency of the "fwifdb"
primitive. The third relation is the teller relation, which also is
implemnted as a binary tree with only one record in its tip-nodes: the
implemented as a binary tree with only one record in its tip-nodes: the
reasons are as for the branch tree. The fourth and last relation is a
simple list of history records.
-}
......@@ -52,5 +52,3 @@ data Dbt = Root Tree Tree Tree [Histrt]
data Msgt = Ok Int | Error Int
deriving (Eq,Show{-was:Text-})
......@@ -12,12 +12,12 @@ float vbm[];
float t,x;
for (i=1; i<=n; i=i+1) {
j0 = i - diag[i] + diag[i-1] + 1; /* column of first non zero elemnt */
j0 = i - diag[i] + diag[i-1] + 1; /* column of first non zero element */
for (j=j0; j<i; j=j+1) {
t = 0.0;
t = 0.0;
k0 = j - diag[j] + diag[j-1] + 1; /* fst.non.zero.col of jth row */
if (j0>k0) k0 = j0;
for (k=k0; k<=j-1; k=k+1) {
......@@ -26,10 +26,10 @@ float vbm[];
}
adr = diag[i]+j-i;
vbm[adr] = (vbm[adr]-t)/vbm[diag[j]];
}
t = 0.0;
t = 0.0;
for (k=j0; k<=(i-1); k=k+1) {
x = vbm[diag[i]+k-i];
t = t + x*x;
......@@ -38,10 +38,10 @@ float vbm[];
vbm[adr] = sqrt ( vbm[adr] - t );
}
}
vbllsolution(n,diag,mvb,b)
......
module Parse(Parse(..),whiteSpace,seperatedBy) where
module Parse(Parse(..),whiteSpace,separatedBy) where
import Data.Char -- 1.3
import StdLib
class Parse a where
......@@ -22,12 +22,12 @@
parseType (ch:str) = (ch,str)
forced n = True
instance (Parse a) => Parse [a] where
parseType more = (map parseLine (seperatedBy ',' (l++",")),out)
parseType more = (map parseLine (separatedBy ',' (l++",")),out)
where (l,']':out) = span' (\x->x/=']') (tail more)
forced = all forced
seperatedBy :: Char -> String -> [String]
seperatedBy ch [] = []
seperatedBy ch xs = twaddle ch (span' (\x->x/=ch) xs)
where twaddle ch (l,_:r) = l:seperatedBy ch r
separatedBy :: Char -> String -> [String]
separatedBy ch [] = []
separatedBy ch xs = twaddle ch (span' (\x->x/=ch) xs)
where twaddle ch (l,_:r) = l:separatedBy ch r
whiteSpace :: String -> String
whiteSpace = dropWhile isSpace
......@@ -133,7 +133,7 @@ result a character string indented by the appropriate amount.
> type Oseq = Int -> Bool -> [Char]
Here are some useful defintions using @oseq@:
Here are some useful definitions using @oseq@:
> o_empty :: Oseq -- An empty oseq
> o_empty indent npend = []
......
......@@ -6,7 +6,7 @@
*
* Each constructors last argument (of the tuple) is a list of
* information attributes that the parser, unparsers, tactics etc use.
*
*
* Each terms' next to last argument is a list of alternative types the the
* term can have to its natutal type.
*
......@@ -104,7 +104,7 @@ eq_sgn (Empty _) (Empty _) = True
eq_sgn (Extend dc1 sg1 _) (Extend dc2 sg2 _)
= eq_dec dc1 dc2 && eq_sgn sg1 sg2
eq_sgn (Combine sg1 sg2 i1 _ _) (Combine sg3 sg4 i2 _ _)
= i1 == i2 && eq_sgn sg1 sg3 && eq_sgn sg2 sg4
......@@ -119,7 +119,7 @@ eq_sgn _ _ = False
{-
* Extract a subterm from a term along with a list of all the
* declarations encounted on the spine down to the subterm.
* declarations encountered on the spine down to the subterm.
* generate an exception if the index does not point at a valid subterm
*
-}
......@@ -244,7 +244,7 @@ replace_trm tm1 tm2 iL
rep_dec (0:iL) (Symbol_dec tm inf)
= Symbol_dec (rep_trm iL tm) inf
rep_dec (0:iL) (Axiom_dec tm inf)
= Axiom_dec (rep_trm iL tm) inf
......@@ -268,7 +268,7 @@ replace_trm tm1 tm2 iL
-}
type Sym_map = Int -> Int -> Int -> [ ITrm ] -> [ Attribute ] -> ITrm
type Const_map = Int -> Int -> Int -> Int -> [ ITrm ] -> [ Attribute ] -> ITrm
......@@ -338,7 +338,7 @@ map_fn map_symbol map_const
map_dec n (Axiom_dec tm inf)
= Axiom_dec (map_trm n tm) inf
map_dec n (Decpair dc1 dc2 inf)
= Decpair (map_dec n dc1) (map_dec (n+1) dc2) inf
......@@ -408,4 +408,3 @@ len_sgn (Extend _ sg _) = 1 + len_sgn sg
len_sgn (Combine sg _ k _ _) = 1+ k + len_sgn sg
len_sgn (Share sg _ _ _ _ _) = 1 + len_sgn sg
......@@ -143,7 +143,7 @@ propagate :: Float -> Force -> AtomState -> AtomState
{-
Ok, I see one problem with this, not general enough! Some better propagators
exist that can use previous atom states. Actually, by using previous atom states,
we will not even need to seperately track the velocities either. Oh well, for now
we will not even need to separately track the velocities either. Oh well, for now
I will stick with that.
-}
......
......@@ -53,7 +53,7 @@ cannot move.
startTour::Tile -> Int -> ChessSet
startTour st size
| (size `mod` 2) == 0 = createBoard size st
| otherwise = error "Tour doesnt exist for odd size board"
| otherwise = error "Tour doesn't exist for odd size board"
\end{code}
......@@ -94,23 +94,23 @@ The Heuristics used in the following function are summerised below :
\begin{enumerate}
\item At any point in the tour, if it is possible to move to the first
tile of the tour, and if by moving to that square produces a
dead end, then their is no point in carrying on with the current
dead end, then there is no point in carrying on with the current
tour because you will never be able to get back to the first square
- dead end.
\item At any point in the tour, if for each of the possible moves you can
take their is only one position that has a single descendent
take, there is only one position that has a single descendent
\footnote{The descendents of a tile is the number of moves you
can make from that tile without falling off the board, or jumping
onto a tile that has already been visited.}, then you {\em must}
take that move otherwise you will be cutting off that tile for a
subsequent move in the tour - dead end.
\item At any point in the tour, if for each of the possible moves you can
take their is more than one position with a single descendent, then
take, there is more than one position with a single descendent, then
you have to abandon the current tour because taking any
of the single descendents tiles will cause the other single descendent
tiles to be unreachable - dead end.
\item At a given point in the tour, if for each of the possible moves you
can take, their are no single descendent tiles, then visit the tiles
can take, there are no single descendent tiles, then visit the tiles
in order of smallest number of descendents first - (don't know why
this works, it just does !!!).
\end{enumerate}
......@@ -127,7 +127,7 @@ descendents board
where
singles = singleDescend board
singleDescend::ChessSet -> [ChessSet]
singleDescend::ChessSet -> [ChessSet]
singleDescend board =[x | (y,x) <- descAndNo board, y==1]
descAndNo::ChessSet -> [(Int,ChessSet)]
......@@ -152,7 +152,7 @@ canJumpFirst board
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A tour is finished if their are 64 pieces on the board (in the case of an 8x8
A tour is finished if there are 64 pieces on the board (in the case of an 8x8
board), and move number 64 of the tour can jump back to the first square
(move number 1).
......
......@@ -103,6 +103,6 @@ depthSearch q growFn finFn
finFn)
\end{code}
{\bf Note :} the above function should be abstracted out into a
seperate search module, but as depth first search is the only
separate search module, but as depth first search is the only
realistic search strategy for the knights tour....
......@@ -16,12 +16,12 @@
\tableofcontents
\section{Introduction.}
A knights tour\cite{bornat:prog1} of a chess board is the trail of
successive knights moves, such that starting at any square on the board,
the knight visits every square on the board once, finishing back at the
square the tour started. Figure \ref{example} shows a tour
for a 8x8 chess board. Note that the tour starts (move @1@) in the
top left hand corner of the board and finishes (move @64@) at a position
A knights tour\cite{bornat:prog1} of a chess board is the trail of
successive knights moves, such that starting at any square on the board,
the knight visits every square on the board once, finishing back at the
square the tour started. Figure \ref{example} shows a tour
for a 8x8 chess board. Note that the tour starts (move @1@) in the
top left hand corner of the board and finishes (move @64@) at a position
where the first move is reachable.
\begin{figure}[htbp]
\begin{center}
......@@ -42,24 +42,24 @@ In many ways this combinatorial search problem is similar to the N-Queen
problem that can be found in most distributions for lazy functional languages.
The difference between the two problems is the size of the search space;
using a brute force approach all the different possible ordering for the
8-Queen problem consists of placing 8 queens in
each of the columns of a chess board - $10^8$ such orderings.
8-Queen problem consists of placing 8 queens in
each of the columns of a chess board - $10^8$ such orderings.
In contrast, all the solutions to the knights tour can be thought of as
a way of numbering all the tiles of a chess board with the numbers
a way of numbering all the tiles of a chess board with the numbers
1 to 64 - $10^{90}$ such orderings.
The aim of this implementation in Haskell is to (1) accustom myself with the
Glasgow Haskell compiler and its cryptic error messages (2) Use Glasgows
literate programming system (3) produce a small, but non trivial program
that hopefully highlights some of the features of the Haskell programming
language.
that hopefully highlights some of the features of the Haskell programming
language.
The heart of this implementation is the module @KnightHeuristic@,
which manipulates an abstract representation of a chess board
(modules @ChessSet@\{@List@,@Array@...\}@.lhs@).
The heart of this implementation is the module @KnightHeuristic@,
which manipulates an abstract representation of a chess board
(modules @ChessSet@\{@List@,@Array@...\}@.lhs@).
As with all data abstraction, this
will hopefully enable a clear understanding of the heuristic used in
the search, and it enables me to play with the representation of the
the search, and it enables me to play with the representation of the
chess board.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -72,22 +72,22 @@ chess board.
\begin{rawlatex}
\begin{tabular}{||c|c|c||r|r|r|r||}
\hline
\hline
\multicolumn{3}{||c||}{Variables}&
\multicolumn{1}{c|}{}&
\multicolumn{1}{c|}{}&
\multicolumn{1}{c|}{}&
\multicolumn{1}{c||}{}\\
\cline{1-3}
ChessBoard & Monomorphic & Sort &
No GC's & \% time GC & Heap used (k) & Total Time\\
ChessBoard & Monomorphic & Sort &
No GC's & \% time GC & Heap used (k) & Total Time\\
\hline\hline
list & no & quickSort & 39 & 22.0 & 28300 & 51.98\\
\hline
\hline
list & no & lazySort & 43 & 23.4 & 29639 & 52.80\\
\hline
\hline
list & no & insertSort & 45 & 23.6 & 30559 & 54.16\\
\hline
\hline
list & no & mergeSort & 46 & 24.0 & 32045 & 57.76\\
\hline
1D array & no & quickSort & 18 & 19.8 & 66894 & 134.54\\
......@@ -95,11 +95,11 @@ list & no & mergeSort & 46 & 24.0 & 32045 & 57.76\\
\multicolumn{7}{||c||}{Program used above \& below different - compare relative change}\\
\hline
list & yes & quickSort & 40 & 22.3 & 28866 & 52.66\\
\hline
\hline
list & yes & lazySort & 44 & 23.8 & 30225 & 53.60\\
\hline
\hline
list & yes & insertSort & 46 & 24.0 & 31294 & 53.38\\
\hline
\hline
list & yes & mergeSort & 45 & 23.7 & 31745 & 57.40\\
\hline
\end{tabular}
......@@ -113,22 +113,22 @@ genericLength = foldl (\n _ -> n+1) 0
\end{code}
, then if we use this function in a context such as below
\begin{code}
let len = genericLength xs
let len = genericLength xs
in (len,len)
\end{code}
, then their is the possiblity that each of the results in the tuple could be
, then there is the possibility that each of the results in the tuple could be
evaluated at different overloadings - the computation would have to be
applied twice. The monomorphism restriction ensures that problems such as the
above do not happen by ensuring that overlaoded pattern bindings are
above do not happen by ensuring that overloaded pattern bindings are
monomorphic in their overloaded variables. This restriction can be lifted by
adding explicit type signatures :
\begin{code}
let len::Num a => a; len = genericLength xs
let len::Num a => a; len = genericLength xs
in (len,len)
\end{code}
I encounted the monomophism restriction in the defintion of @notElem@.
The first of the definitions breaks the monomorphism restriction,
the second doesnt - why is this so (not convinced by the reports
I encountered the monomorphism restriction in the definition of @notElem@.
The first of the definitions breaks the monomorphism restriction,
the second doesn't - why is this so (not convinced by the reports
description)???
\begin{code}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment