Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created October 15, 2010 07:33
Show Gist options
  • Select an option

  • Save oskimura/627783 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/627783 to your computer and use it in GitHub Desktop.
module HarfAdder where
import Data.Bits
import Data.Word
import Control.Applicative
harfAdder True True = (False,True)
harfAdder True False = (True, False)
harfAdder False True = (True, False)
harfAdder False False = (False,False)
fullAdder =
(\ a b c -> let (a',b') = harfAdder a b
in let (a'',b'') = harfAdder a' c in (a'' , b'||b''))
phi :: (Bool,[Bool]) -> (Bool,Bool) -> (Bool,[Bool])
phi (c,xs) (a,b) = let (s,c') = fullAdder a b c in (c',s:xs)
plus xs ys = let (c, ss) = g xs ys in c:ss
where
g = (f .) . aux
f = foldl phi (False,[])
aux :: [Bool] -> [Bool] -> [(Bool,Bool)]
aux = zipWith (,)
@oskimura

Copy link
Copy Markdown
Author

Haskellでbit加算器
Boolをbitにみたててある

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment