Skip to main content

Posts

Showing posts from May, 2008

NumberCheck in haskell

import System.Environment
import Data.Char

main = do
arg:_ <- getArgs
putStrLn (arg ++ " is " ++ (result arg))
where result arg = if check arg then "correct" else "incorrect"
check arg = dotOrDigit `all` arg && oneOrZeroDots arg
dotOrDigit = (`elem` ['0'..'9'] ++ ['.'])
oneOrZeroDots = (<=1) . length . (filter ('.'==))

logs display, little experiment

this code ...


module LogDiffMarker where

type ReferenceWords = [String]
type Lines = [Line]
type Line = String

mark_diffrent_words :: (ReferenceWords, Lines) -> Line -> (ReferenceWords, Lines)
mark_diffrent_words (ref,i) line = (next_ref, i ++ [unwords line_with_em])
where (line_with_em, next_ref) = mark_diffrences (words line) ref ([],[])
mark_diffrences l1 [] (line_acc, ref_acc) = (line_acc ++ ["<b>"] ++ l1 ++ ["</b>"], ref_acc ++ l1)
mark_diffrences [] r (line_acc, ref_acc) = (line_acc, ref_acc)
mark_diffrences (h1:t1) (h2:t2) (line_acc, ref_acc)
| h1 == h2 = mark_diffrences t1 t2 (line_acc ++ [h1] ,ref_acc ++ [h2])
| otherwise = mark_diffrences t1 t2 (line_acc ++ ["<b>" ++ h1 ++ "</b>"],ref_acc ++ [h1])

mark_diffrent_lines :: Lines -> Lines
mark_diffrent_lines = (["<pre>"]++) . (++["</pre>"]) . snd . (foldl mark…