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
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
2006-08-07
In normal Haskell you can use what is possibly the most obscure
Haskell98 feature, the default keyword, to modify how type
defaulting works, and resolve ambiguities -- but only for numeric
classes. The result is less type signatures, as below:
default(Double)
main = print $ 2 + 1
In ghci, this defaulting has been extended to the Eq, Ord and Show
classes, so we can write, in ghci:
> reverse []
[]
and ghci will find the right Show instance.
Now, in
Noticed today that in the ghc 6.5 branch, the following program is valid:
main :: IO String
main = return "hello, world"
This works for any return type, in Show, it seems. (Except, notably, ()).
$ runhaskell A.hs
"hello, world"
/home ::
/haskell ::
permalink ::
rss