Haskell

17 thoughts
last posted Feb. 21, 2014, 6:53 p.m.

14 earlier thoughts

0

A little shifting exercise today:

```haskell shiftR :: [a] -> [a] shiftR xs = last xs : init xs shiftR [] = []

shiftL :: [a] -> [a] shiftL (x:xs) = xs ++ [x] shiftL [] = []

shiftBy :: ([a] -> [a]) -> [a] -> Int -> [a] shiftBy f xs n = head $ drop n $ iterate f xs

shiftByL :: [a] -> Int -> [a] shiftByL = shiftBy shiftL

shiftByR :: [a] -> Int -> [a] shiftByR = shiftBy shiftR ```

What's the development process?

With a few terminals open:

  • emacs open in one window
  • ghci open on another window

I do this:

  1. Load module into ghci: :l shift
  2. edit in emacs
  3. reload in ghci :r after each edit

Once things were working, I moved to clean up the style using hlint.

Good future additions:

  1. QuickCheck suite
  2. Criterion benchmarks
  3. Packaging: Setup.hs and shift.cabal

2 later thoughts