clock icon indicating copy to clipboard operation
clock copied to clipboard

Lift instance

Open OlivierSohn opened this issue 7 years ago • 6 comments

Hello,

I would need TimeSpec to have a Lift instance. Would you consider taking a PR on that subject considering it adds a dependency on template-haskell?

Note that I can live without it for the moment, by manually implementing the Lift instance on the wrapper type.

OlivierSohn avatar May 07 '18 14:05 OlivierSohn

Is template-haskell available everywhere? How widely is it installed? How does it interact with cross-compilation?

Also why not add your manual Lift instance in a PR without referencing template-haskell?

CetinSert avatar Jul 03 '18 06:07 CetinSert

Also why not add your manual Lift instance in a PR without referencing template-haskell?

The Lift class is in Language.Haskell.TH.Syntax, this is why we need to reference template-haskell.

OlivierSohn avatar Jul 03 '18 08:07 OlivierSohn

Btw, the Liftinstance I implemented for my type is:

newtype Time a b = Time TimeSpec
  deriving(Generic, Eq, Ord)
instance Lift (Time a b) where
  lift (Time (TimeSpec s ns)) = [| Time (TimeSpec $(lift s) $(lift ns)) |]

So the Liftinstance for TimeSpec should be:

instance Lift TimeSpec where
  lift (TimeSpec s ns) = [| TimeSpec $(lift s) $(lift ns) |]

OlivierSohn avatar Jul 03 '18 08:07 OlivierSohn

Is template-haskell available everywhere? How widely is it installed? How does it interact with cross-compilation?

It's available on hackage, do you mean "which platforms are supported?"

I have no idea about cross compilation interactions as I don't cross-compile.

OlivierSohn avatar Jul 03 '18 08:07 OlivierSohn

@OlivierSohn - just got my hackage account back in shape and uploaded a new version of clock!

  1. Is there a way to define a Lift instance without template-haskell?
  2. Why exactly is template-haskell needed?

CetinSert avatar Apr 30 '19 07:04 CetinSert

The Lift class is defined in the package template-haskell, hence there is no way to define an instance without depending on the package. But the package is a core library included with GHC, so depending on it doesn't add any footprint. There is the DeriveLift extension so it is just importing the class and writing ... deriving (..., Lift). https://github.com/corsis/clock/commit/5fa98d9f9461d48d75e55433cbef7aacbf6fe11c

But you can also define an instance easily using StandaloneDeriving, so I don't know if it's worth it. Most users will not be using this library with Template Haskell.

Mathnerd314 avatar May 12 '21 22:05 Mathnerd314