trit == char || '+'|'0'|'-'
pseudo_trit == char || '+'|'#'[half]|'0'|'%'[minus-half]|'-'

tritstream == [trit]
pseudo_tritstream == [pseudo_trit]

real == tritstream
pseudo_real == pseudo_tritstream

average :: real -> real -> real
  average x y = correct (naive_average x y)

naive_average :: real -> real -> pseudo_real
  naive_average (xh:xt) (yh:yt) = trit_average xh yh : naive_average xt yt
                                  where
                                  trit_average '+' '+' = '+'
                                  trit_average '+' '0' = '#'
                                  trit_average '+' '-' = '0'
                                  trit_average '0' '+' = '#'
                                  trit_average '0' '0' = '0'
                                  trit_average '0' '-' = '%'
                                  trit_average '-' '+' = '0'
                                  trit_average '-' '0' = '%'
                                  trit_average '-' '-' = '-'

correct :: pseudo_real -> real
  correct ('+':rest) = '+' : correct rest
  correct ('#':'+':rest) = '+' : correct('0':rest)
  correct ('#':'#':rest) = '+' : correct('%':rest)
  correct ('#':'0':rest) = '0' : correct('+':rest)
  correct ('#':'%':rest) = '0' : correct('#':rest)
  correct ('#':'-':rest) = '0' : correct('0':rest)
  correct ('0':rest) = '0' : correct rest
  correct ('%':'+':rest) = '0' : correct('0':rest)
  correct ('%':'#':rest) = '0' : correct('%':rest)
  correct ('%':'0':rest) = '0' : correct('-':rest)
  correct ('%':'%':rest) = '-' : correct('#':rest)
  correct ('%':'-':rest) = '-' : correct('0':rest)
  correct ('-':rest) = '-' : correct rest







fix :: (* -> *) -> *
  fix f = f (fix f)
