Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Haskell hacking
[go: Go Back, main page]


Haskell Hacking: a journal of Haskell programming



2006-08-26

Theorems for free and undoing monads in lambdabot

Two new fun plugins for lambdabot this week. The first, by Andrew Bromage, is @free, a free theorems generator. Given a function's type, the plugin returns theorems that hold for that function:

lambdabot> free sortBy :: (a -> a -> Ordering) -> [a] -> [a]
g x y = h (f x) (f y) => map f . sortBy g = sortBy h . map f

lambdabot> free foldl :: (a -> b -> a) -> a -> [b] -> a
f . h x = k (f x) . g => f . foldl h y = foldl k (f y) . map g

lambdabot> free filter :: (a -> Bool) -> [a] -> [a]
g x = h (f x) => map f . filter g = filter h . map f

lambdabot> free fmap :: (a -> b) -> F a -> F b
g . h = k . f => $map_F g . fmap h = fmap k . $map_F f

lambdabot> free sequence_ :: [M a] -> M ()
g y = y => mapM g (sequence_ x) = sequence_ (map (mapM f) x)

lambdabot> free unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
 (((
    g (fst y) = fst z && f (snd y) = snd z
  ) =>
    p y = z
  ) =>
    mapMaybe p (h x) = k (f x)
  ) =>
    map g . unfoldr h = unfoldr k . f

Cool, huh? Free properties for your code! (Lots of properties checkable with QuickCheck perhaps..)

The second new plugin, written by Spencer Janssen, is @undo, a desugarer for do-notation, meaning we can plug monadic syntax into other lambdabot plugins:

lambdabot> undo do x <- f ; y <- g ; return (mapM_ k $ x ++ y)
f >>= \ x -> g >>= \ y -> return (mapM_ k $ x ++ y)

which we can then feed to the pointfree plugin:

lambdabot> compose pl undo do x <- f ; y <- g ; return (mapM_ k $ x ++ y)
(`fmap` g) . (mapM_ k .) . (++) =<< f

or find the type of:

lambdabot> compose type compose pl undo \f g k -> do x <- f ; y <- g ; return (mapM_ k $ x ++ y)
 forall a (m :: * -> *) b (m1 :: * -> *).
        (Monad m, Monad m1) =>
            m1 [a] -> m1 [a] -> (a -> m b) -> m1 (m ())

Haskell is fun!

/home :: /haskell :: permalink :: rss

What mp3 players should be like

My new M-Cody M20 mp3 player arrived today from the UK. Mmm... design.
MCody M20

Its tiny, smaller than a nano ipod, and when idle is completely black -- the OLED screen disappears. 2G is plenty, and it also has an FM tuner with presets, as well as a text file viewer.

The sound is great (after ditching the headphones it came with, and plugging in some good Sennheiser ones). The touch sensitive case took an hour or so to really get the handle of, and it seems quite intuitive now.

Had a bit of trouble at the start using it under OpenBSD (I managed to mangle the partition table on the device, and couldn't produce a vfat fs anyway), but under Linux things work perfectly, appearing like a usb stick.

So, all in all: tiny, beautiful, functional.

/home :: /hardware :: permalink :: rss

Haskell on 32 processors and beyond

Roman Leshchinskiy mentioned yesterday that he managed to get GHC running SMP Data Parallel Haskell on a 32 cpu Sun E6900, with memory, 80G real and 500G swap (a bargain at somewhere around $250,000 US for this midrange server)

Its fun watching GHC Haskell scale so well..

An aside: DPH uses stream fusion to automatically fuse concurrent array code. In Data.ByteString we adapted the rewrite rules and code, to instead fuse code over flat, unboxed Word8 arrays, for fast strings.

/home :: /haskell :: permalink :: rss

Archives

Recommended

Blog Roll

Syndicate