jcristovao / newtype-generics

A typeclass and set of functions for working with newtypes.
10 stars 11 forks source link

missing instance for `Identity` (which can be found in base) #2

Closed imz closed 7 years ago

imz commented 9 years ago

In the documentation, it is claimed there are instances for the types from base.

But I miss an instance for Identity from Control.Monad.Identity (which is actually defined and imported from Data.Functor.Identity from base).

Can it be added without problems?

imz commented 9 years ago

My quick workaround in my code for now is like this:

{-# LANGUAGE StandaloneDeriving, DeriveGeneric #-}

import Control.Newtype
import Control.Monad.Identity
import GHC.Generics

deriving instance Generic (Identity a)
instance Newtype (Identity a)

Then I can write something like:

unsafeFromString =
    under Identity 
        (\v' -> do (String t) <- v'
               return t)

(as an implemntation of my (bad) idea how to suppress a warning about a non-exhaustive pattern match). It's here just to serve as an example.

sjakobi commented 7 years ago

Thanks for the suggestion! :+1: Fixed in https://github.com/jcristovao/newtype-generics/commit/3b803ac0cb87b214411a5cb6b52e4cac300b1c75.

sjakobi commented 7 years ago

Published in v0.5.1.