[Haskell-cafe] newtype deriving Alternative

Ryan Ingram ryani.spam at gmail.com
Wed Oct 14 18:12:27 EDT 2009


Works for me on GHC6.10.4:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module NewtypeDerive where
import Control.Applicative

newtype Foo f a = Foo (f a) deriving (Functor, Applicative, Alternative)
newtype Bar a = Bar [a] deriving (Functor, Applicative, Alternative)

  -- ryan

On Wed, Oct 14, 2009 at 2:16 PM, Martijn van Steenbergen <
martijn at van.steenbergen.nl> wrote:

> Hello café,
>
> I've never written an Alternative instance for a newtype yet that doesn't
> look like this:
>
>  instance Alternative T where
>>  empty = T empty
>>  T x <|> T y = T (x <|> y)
>>
>
> Why does newtype deriving not work for Alternative? (It works fine for
> Monoid.)
>
> Thanks,
>
> Martijn.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091014/3a798730/attachment.html


More information about the Haskell-Cafe mailing list