[Haskell-cafe] ANN: unfoldable-0.4.0

Roman Cheplyaka roma at ro-che.info
Thu Apr 26 20:42:43 CEST 2012


This is also quite similar to what we have in SmallCheck:
https://github.com/feuerbach/smallcheck/blob/master/Test/SmallCheck/Series.hs

Not sure how to exploit this, though.

* Sjoerd Visscher <sjoerd at w3future.com> [2012-04-26 00:32:28+0200]
> I am pleased to announce the 5th version of the unfoldable package. (This is the first announcement, you didn't miss anything.)
> http://hackage.haskell.org/package/unfoldable-0.4.0
> 
> Just as there's a Foldable class, there should also be an Unfoldable class. This package provides one:
> 
>   class Unfoldable t where
>     unfold :: Unfolder f => f a -> f (t a)
> 
> Writing instances of Unfoldable is similar to writing Traversable instances. For example, given a data type
> 
>   data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a)
> 
> a suitable instance would be
> 
>   instance Unfoldable Tree where
>     unfold fa = choose
>       [ pure Empty
>       , Leaf <$> fa
>       , Node <$> unfold fa <*> fa <*> unfold fa
>       ]
> 
> The choose function comes from the Unfolder class:
> 
>   class Applicative f => Unfolder f where
>     choose :: [f x] -> f x
> 
> (If f is an Alternative instance, choose is simply Data.Foldable.asum.)
> 
> Different unfolders provide different ways of generating values, for example:
>  - Random values
>  - Enumeration of all values (depth-first or breadth-first)
>  - Convert from a list
>  - An implementation of QuickCheck's arbitrary should also be possible (still working on that)
> 
> Some examples can be found in the examples directory in the github repo:
> https://github.com/sjoerdvisscher/unfoldable
> 
> Ideas and comments are welcome!
> 
> greetings,
> Sjoerd

-- 
Roman I. Cheplyaka :: http://ro-che.info/



More information about the Haskell-Cafe mailing list