type-synonyms

Type synonyms “not in scope” when using Template Haskell

对着背影说爱祢 提交于 2019-12-23 10:49:31
问题 I am getting a strange error about a data type being "not in scope" when using Template Haskell. Here is my Main.hs file: {-# LANGUAGE TemplateHaskell #-} module Main where import Control.Lens import Data.Aeson import Data.Aeson.TH type Foo = Bar data Baz = Baz $(deriveJSON defaultOptions ''Baz) -- $(makeLenses ''Baz) data Bar = Bar main :: IO () main = print "hello" When trying to compile it, I get the following error: test-0.1.0.0: configure Configuring test-0.1.0.0... test-0.1.0.0: build

When (if ever) can type synonyms be partially applied?

走远了吗. 提交于 2019-12-08 15:15:19
问题 Apparently a bit absent-mindedly, I wrote something like the following: {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE TypeFamilies #-} class Foo f where type Bar f :: * retbar :: Bar f -> IO f type Baz f = (Foo f, Eq f) -- WithBar :: * -> (*->Constraint) -> * -> Constraint type WithBar b c f = (c f, Bar f ~ b) instance Foo () where type Bar () = () retbar = return naim :: WithBar () Baz u => IO u -- why can I do this? naim = retbar () main = naim :: IO () Only after successfully compiling, I