Getting associated type synonyms with template Haskell

Can Template Haskell find out the names and/or the declarations of the associated type synonyms declared in a type class? I expected reify would do what I want, but it doesn't seem to provide all the necessary information. It works for getting function type signatures: % ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help ... Prelude> -- I'll be inserting line breaks and

使用模板Haskell获取关联的类型同义词

Can Template Haskell可以找出类型类中声明的关联类型同义词的名称和/或声明吗? 我期望reify会做我想做的事情,但它似乎并没有提供所有必要的信息。 它适用于获取函数类型签名: % ghci GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help ... Prelude> -- I'll be inserting line breaks and whitespace for clarity Prelude> -- in all GHCi output. Prelude> :set -XTemplateHaskell Prelude> i

What's so bad about Template Haskell?

It seems that Template Haskell is often viewed by the Haskell community as an unfortunate convenience. It's hard to put into words exactly what I have observed in this regard, but consider these few examples Template Haskell listed under "The Ugly (but necessary)" in response to the question Which Haskell (GHC) extensions should users use/avoid? Template Haskell considered a te

关于模板哈斯克尔有什么不好?

Haskell社区经常认为模板Haskell是一种不幸的方便。 在这方面,我很难将词语完全放在文字上,但请考虑这几个例子 模板Haskell在“The Ugly(but necessary)”中列出,以回答用户使用/避免哪些Haskell(GHC)扩展的问题? 模板Haskell在newtype的值线程(库邮件列表)的Unboxed Vectors中考虑了临时/劣势解决方案, Yesod经常因为过度依赖Template Haskell而受到批评(请参阅博客文章以回应这种观点) 我已经看过各种博客

Why doesn't Safe Haskell support Template Haskell?

The documentation for Safe Haskell states: [...] Unfortunately Template Haskell can be used to subvert module boundaries and so could be used gain access to this constructor. [...] The use of the -XSafe flag to compile the Danger module restricts the features of Haskell that can be used to a safe subset. This includes disallowing unsafePerfromIO, Template Haskell,[...] Used as a macro syste

为什么不安全的Haskell支持模板Haskell?

Safe Haskell的文档声明: [...]不幸的是,模板Haskell可以用来破坏模块的边界,所以可以用来访问这个构造函数。 [...]使用-XSafe标志编译Danger模块会限制可用于安全子集的Haskell功能。 这包括禁止unsafePerfromIO,Template Haskell,[...] 作为一个将AST转换为另一个AST的宏系统,难道不可能简单地将TH限制在Haskell的安全子集中​​,并且还要将产生的AST限制到这个子集? 在您链接的页面上再向下一点: TemplateHa

Why is GHC emitting incorrect "redundant constraint" warning here?

As per the title I'm curious as to why GHC is emitting a warning about a redundant constraint when its removal makes the code no longer compile. {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-}

为什么GHC在这里发出错误的“冗余约束”警告?

根据标题,我很好奇GHC为什么在删除代码时不再编译时发出关于冗余约束的警告。 {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANG

instance only) of typeclasses in Agda

Agda's mixiture of records and the instance keyword give us behaviour similar to that of Haskell's typeclasses. Moreover, ignoring the instance keyword, we can have more than one instance for the same type --- something we cannot do in Haskell. I am at a point where I need Haskell's one-instance only requirement, but in Agda. Is there an compiler option or some trick/heuristic to

Agda中的类型类的实例)

Agda的记录组合和instance关键字使我们的行为与Haskell的类型类相似。 此外,忽略instance关键字,我们可以为同一类型提供多个实例 - 这是我们在Haskell中无法做到的。 我处于一个需要Haskell一个实例的要求,但在Agda。 有没有编译器选项或一些技巧/启发式强制执行此? 现在我采取的方法是, record Yo (n : ℕ) : Set where field sem : (some interesting property involving n) open Yo {{...}} postulate Uniq

Ambigous instance resolution in Haskell

Introduction and example use case Hello! I've got a problem in Haskell. Let's consider following code class PolyMonad m1 m2 m3 | m1 m2 -> m3 where polyBind :: m1 a -> (a -> m2 b) -> m3 b which just declares a poly monad binding. A good example use case scenario would be: newtype Pure a = Pure { fromPure :: a } deriving (Show) instance PolyMonad Pure Pure Pure wher

Haskell中的恶意实例解析

介绍和示例用例 你好! 我在Haskell中遇到了一个问题。 让我们考虑下面的代码 class PolyMonad m1 m2 m3 | m1 m2 -> m3 where polyBind :: m1 a -> (a -> m2 b) -> m3 b 它只是声明一个poly monad绑定。 一个很好的示例用例场景是: newtype Pure a = Pure { fromPure :: a } deriving (Show) instance PolyMonad Pure Pure Pure where polyBind a f = f (fromPure a) instance PolyMonad Pure IO

Flexible instances needed?

I want to write a Convertible instance for a Haskell type to its C representation It looks like this: instance Convertible Variable (IO (Ptr ())) where Now GHC complains: Illegal instance declaration for `Convertible Variable (IO (Ptr ()))' (All instance types must be of the form (T a1 ... an) where a1 ... an are *distinct type variables*, and eac

需要灵活的实例?

我想为它的C表示写一个Haskell类型的Convertible实例 它看起来像这样: instance Convertible Variable (IO (Ptr ())) where 现在GHC抱怨说: Illegal instance declaration for `Convertible Variable (IO (Ptr ()))' (All instance types must be of the form (T a1 ... an) where a1 ... an are *distinct type variables*, and each type variable appears at most once i

Automatic instance deriving after declaration

In Haskell, when defining a data type you can choose to automatically derive some instances, but can I defer the automatic deriving, perhaps even put it in another library? Here is an example: Automatic deriving in Haskell is a real time saver! module MoneyModule where data Money = Money Int deriving Show Now I wish to use the MoneyModule , but I also want a Read instance for Money : mo

声明后自动导出实例

在Haskell中,当定义数据类型时,你可以选择自动派生一些实例,但是我可以推迟自动派生,甚至可以把它放在另一个库中? 这里是一个例子: 自动获取Haskell是一个实时的节省! module MoneyModule where data Money = Money Int deriving Show 现在我想使用MoneyModule ,但我也想要一个Money的Read实例: module ExternalModule where instance Read Money where read = error "Can't this be done automatically in

CPP extension and multiline literals in Haskell

Is it possible to use CPP extension on Haskell code which contains multiline string literals? Are there other conditional compilation techniques for Haskell? For example, let's take this code: -- If the next line is uncommented, the program does not compile. -- {-# LANGUAGE CPP #-} msg = "Hello Wor ld!" main = putStrLn msg If I uncomment {-# LANGUAGE CPP #-} , then GHC refutes thi

CPP扩展和Haskell中的多行文字

是否可以在包含多行字符串的Haskell代码上使用CPP扩展? Haskell还有其他的条件编译技术吗? 例如,我们来看下这段代码: -- If the next line is uncommented, the program does not compile. -- {-# LANGUAGE CPP #-} msg = "Hello Wor ld!" main = putStrLn msg 如果我取消注释{-# LANGUAGE CPP #-} ,那么GHC会用一个词法错误来驳斥这个代码: [1 of 1] Compiling Main ( cpp-multiline.hs, cpp-mul

What is the difference between . (dot) and $ (dollar sign)?

What is the difference between the dot (.) and the dollar sign ($) ?. As I understand it, they are both syntactic sugar for not needing to use parentheses. The $ operator is for avoiding parentheses. Anything appearing after it will take precedence over anything that comes before. For example, let's say you've got a line that reads: putStrLn (show (1 + 1)) If you want to get rid o

有什么区别。 (点)和$(美元符号)?

点(.)和美元符号($)之间的区别是什么? 据我了解,它们都是不需要使用括号的语法糖。 $运算符用于避免括号。 之后出现的任何内容都将优先于之前的任何内容。 例如,假设您有一行内容如下: putStrLn (show (1 + 1)) 如果你想摆脱这些括号,下面的任何一行也会做同样的事情: putStrLn (show $ 1 + 1) putStrLn $ show (1 + 1) putStrLn $ show $ 1 + 1 该主要目的. 运算符不是为了避免括号,而是为了链接函数。 它可