||NAMES DEFINED IN THIS FILE ARE NOT IN SCOPE FOR USERS - they are part
||of the internal mechanisms of the Miranda system

||the following three identifiers are "untypeable" and defined internally
||changetype::*->**  ||primitive function, semantically equivalent to id
||first::*->**	||gets first element of a tuple
||rest::*->**	||gets rest of a tuple (i.e. without first component)
||offside::[char] ||used by indent, see below

  diagonalise :: [[*]]->[*]  ||used by [//] comprehensions
  diagonalise x = diag 1 x   ||when nested does "cantorian" diagonalisation
  diag n [] = []
  diag n x = map hd px++diag (#px+1)rest, otherwise
	     where
	     px = filter (~=[]) (take n x)
	     rest = map tl px ++ drop n x
  listdiff::[*]->[*]->[*] ||listdiff defines the action of "--"
  listdiff x [] = x
  listdiff x (b:y) = listdiff (remove b x) y
  remove b [] = []
  remove b (a:x) = x, if a=b
                 = a:remove b x, otherwise
  showbool::bool->[char]
  showbool True = "True"
  showbool false = "False"
||shownum now defined internally
  base r x = "0", if x=0 ||base still used by showchar
           = f x, otherwise
             where
             f 0 = []
             f n = f(n div r) ++ [mkdigit(n mod r)]
  mkdigit n = decode(n + code '0'), if n<10
            = decode(n - 10 + code 'a'), if 10<=n<36
  showchar::char->[char]
  showchar '\'' = "'\\''"
  showchar '"' = "'\"'"
  showchar x = "'" ++ charname x ++ "'", otherwise
||note - charname has the right conventions for inside string quotes
||i.e. " is escaped and ' is not escaped - showchar inverts this
  charname '\\' = "\\\\"
  charname '"'  = "\\\""
  charname x = [x], if 32<= code x < 127
  charname '\n' = "\\n"
  charname '\t' = "\\t"
  charname '\b' = "\\b"
  charname '\f' = "\\f"
  charname '\r' = "\\r"
  charname x = "\\"++pad++base 10(code x)
	       where
	       pad = "00", if code x<10
		   = "0", if code x<100
		   = "", otherwise
  showlist::(*->[char])->[*]->[char]
  showlist f x = '[':rest
		 where
		 rest = "]", if x=[]
		      = f(hd x)++foldr g "]" (tl x), otherwise
	         g a s = ',':f a++s
  showstring::[char]->[char]
  showstring x = "\"" ++ concat(map charname x) ++ "\""
  shownum1::num->[char]
  shownum1 n = "("++shownum n++")", if n<0
	     = shownum n, otherwise
  showparen::(*->[char])->*->[char]
  showparen f x = "("++f x++")"
  showpair::(*->[char])->(**->[char])->***->[char]
  showpair f1 f2 tup = f1(first tup)++","++f2(rest tup)
  showvoid::()->[char]
  showvoid () = "()"
  showfunction::(*->**)->[char]
  showfunction x = "<function>"
  showabstract::*->[char]
  showabstract x = "<abstract ob>"
  showwhat::*->[char]
  showwhat x = error "undeclared show-function", if x=x
||the following function is used to implement the offside rule (under %bnf)
  indent :: *->**->** || * is type of `col' function
  indent = changetype indent1
  indent1 col f ((a,s):x) 
    = (reconstruct.f)((a,s):cutoff col (col s) x), if a~=offside
  indent1 col f x = f x
  cutoff col n = f
  	         where
  	         f ((a,s):x) = (a,s):f x, if col s>=n
                             = (offside,s):(a,s):x, otherwise
                 f [] = []
  reconstruct (m:x) = m:f x
                      where
  		      f ((a,s):x) = x, if a=offside
                      f (t:x) = t:f x
  		      f [] = []
  reconstruct fail = fail  ||internal repn of failure is a non-CONS object
||offside is defined internally and differs from every string
