Type quantifiers in Haskell functions

Suppose I have two Haskell functions of the following types, with ExplicitForAll activated, f :: forall a. (a -> Int) g :: forall a. (Int -> a) It seems to me that the type of g is isomorphic to Int -> (forall a. a) , because for example the type of g(2) is forall a. a forall a. a . However, the type of f doesn't look isomorphic to (forall a. a) -> Int . f is a polymorphic f

在Haskell函数中输入量词

假设我有两个以下类型的Haskell函数,ExplicitForAll被激活, f :: forall a. (a -> Int) g :: forall a. (Int -> a) 在我看来, g的类型同构于Int -> (forall a. a) ,因为例如g(2)的类型是全部forall a. a forall a. a 。 然而, f的类型看起来不同构于(forall a. a) -> Int 。 f是一个多态函数,它知道在每个输入类型a上计算什么,在数学上我猜它应该是一个函数族; 但我不认为它可以处理所有类型的单一参

Is it possible to write this function in Haskell?

I'm learning dependent types: In Haskell I have defined the canonical type data Vec ∷ Type → Nat → Type where Nil ∷ Vec a Z (:-) ∷ a → Vec a n → Vec a (S n) and implemented most of the functions from Data.List however I don't know how to write, if possible at all, functions like delete ∷ Eq a ⇒ a → Vec a n → Vec a (??) since the length of the result is not known. I have found it

是否有可能在Haskell中编写这个函数?

我正在学习依赖类型:在Haskell中,我定义了规范类型 data Vec ∷ Type → Nat → Type where Nil ∷ Vec a Z (:-) ∷ a → Vec a n → Vec a (S n) 并实现了Data.List大部分函数,​​但是我不知道如何编写,如果可能的话,函数就像 delete ∷ Eq a ⇒ a → Vec a n → Vec a (??) 因为结果的长度是未知的。 我已经在Agda中找到了它,并以此方式实施 delete : {A : Set}{n : Nat}(x : A)(xs : Vec A (suc n)) → x ∈ xs → Vec A n d

How to understand the function "(.)(.)" in Haskell

I am a beginner in Haskell and I come across the function (.)(.) , I use :t to get its type in GHCi: :t (.)(.) (.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c How to understand the type (.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c here? I am very confused. This is a partial application of the composition operator to the composition opera

如何理解Haskell中的函数“(。)(。)”

我是Haskell的初学者,我遇到了函数(.)(.) ,我使用:t在GHCi中获得它的类型: :t (.)(.) (.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c 如何在这里理解类型(.)(.) :: (a -> b -> c) -> a -> (a1 -> b) -> a1 -> c ? 我很困扰。 这是组合运算符对组合运算符本身的部分应用。 一般来说,我们知道如果我们将(.)应用于某些函数f :: x -> y ,那么 >>> :t (.)

Best practices for distributing a Haskell application and updating it

tl;dr About a week ago I released the 0.1.0.0 package for my first non-trivial Haskell project. I want the executable to be easy to install and upgrade, even for non-Haskellers. In the README, I suggested installing using cabal install . Is this a mistake? Context I had heard of "Cabal hell", but didn't realize how darn hard it would be for users to upgrade a globally insta

分发Haskell应用程序并进行更新的最佳实践

TL;博士 大约一周前,我为我的第一个非平凡的Haskell项目发布了0.1.0.0包。 我希望可执行文件易于安装和升级,即使对于非Haskellers也是如此。 在README中,我建议使用cabal install 。 这是一个错误吗? 上下文 我听说过“Cabal hell”,但并没有意识到,即使我保守地没有实际更改.cabal文件中的任何版本依赖关系,用户也无法升级全局安装的软件包副本。 最后,我走下了一个深深的兔子洞,试图从0.1.0.0更新到0.2.0.0。

Type safe lookup on heterogeneous lists in Haskell

I want to develop a type safe lookup function for the following data type: data Attr (xs :: [(Symbol,*)]) where Nil :: Attr '[] (:*) :: KnownSymbol s => (Proxy s, t) -> Attr xs -> Attr ('(s , t) ': xs) The obvious lookup function would be like: lookupAttr :: (KnownSymbol s, Lookup s env ~ 'Just t) => Proxy s -> Attr env -> t lookupAttr s ((s',t) :* env') = cas

在Haskell的异类列表中键入安全查找

我想为以下数据类型开发一个类型安全的查找函数: data Attr (xs :: [(Symbol,*)]) where Nil :: Attr '[] (:*) :: KnownSymbol s => (Proxy s, t) -> Attr xs -> Attr ('(s , t) ': xs) 显而易见的查找功能如下所示: lookupAttr :: (KnownSymbol s, Lookup s env ~ 'Just t) => Proxy s -> Attr env -> t lookupAttr s ((s',t) :* env') = case sameSymbol s s' of Just Refl

mod have to use full names for types?

I'm trying to use the ghc-mod vim plugin to do type/syntax checking etc. However, I found that ghc-mod always uses full paths of types in the error messages, for example: test.hs|71 col 13 error| Couldn't match type ‘Data.Text.Internal.Text’ || with ‘[GHC.Types.Char]’ || Expected type: container

国防部必须使用全名的类型?

我正在尝试使用ghc-mod vim插件来进行类型/语法检查等。但是,我发现ghc-mod总是在错误消息中使用类型的完整路径,例如: test.hs|71 col 13 error| Couldn't match type ‘Data.Text.Internal.Text’ || with ‘[GHC.Types.Char]’ || Expected type: containers-0.5.6.2:Data.Map.Base.Map || [GHC.Types.Ch

GHC TypeLits without values

Trying to design a type-driven API, I've been trying to get something like the following working (using much more complicated code/attempts, this is stripped down to the minimum required to clarify what I'm looking for): {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} module Main where import Data.Proxy import GHC.TypeLits type Printer (s :: Symbol) = IO () concrete :: Pri

GHC TypeLits没有值

试图设计一个类型驱动的API,我一直试图得到像下面这样的工作(使用更复杂的代码/尝试,这被剥离到最低限度要求澄清我在找什么): {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} module Main where import Data.Proxy import GHC.TypeLits type Printer (s :: Symbol) = IO () concrete :: Printer "foo" concrete = generic generic :: KnownSymbol s => Printer s generic = putStrLn (symbolVal (Pro

What GHC optimization is responsible for duplicating case expressions?

Given the following code: {-# OPTIONS_GHC -funbox-strict-fields #-} module Test where data X = X !Int !Int test (X a b) (X c d) = X (max a c) (max b d) GHC generates this core when compiling with optimizations (renamed to make reading easier): test test = u v -> case u of x { X y z -> case v of c { X d e -> case tagToEnum# (<=# y d) of _ { False ->

什么GHC优化负责复制案例表达式?

给出以下代码: {-# OPTIONS_GHC -funbox-strict-fields #-} module Test where data X = X !Int !Int test (X a b) (X c d) = X (max a c) (max b d) GHC在进行优化编译时生成此核心(重命名以便于阅读): test test = u v -> case u of x { X y z -> case v of c { X d e -> case tagToEnum# (<=# y d) of _ { False -> case tagToEnum# (<=# z e) of _ { Fals

Haskell Servant and streaming

I am trying to add a functionality to my servant server that would get a file from Amazon S3 and stream it back to the user. Because files can be big I don't want to download them locally and then serve them to clients, I'd rather prefer to stream them directly from S3 to clients. I use Amazonka for what I do with S3 and I can get a stream for an S3 file as a Conduit sink. But now I

Haskell仆人和流媒体

我试图将功能添加到我的servant服务器将获得来自亚马逊S3文件和流回给用户。 由于文件可能很大,我不想在本地下载它们,然后将它们提供给客户端,我宁愿将它们直接从S3传输到客户端。 我使用Amazonka来处理S3所做的事情,并且我可以为S3文件作为Conduit器获取流。 但现在我不知道怎么去从Sink到EitherT ServantErr IO a 。 任何人都可以解释我如何去做,或者告诉我一些如何做到的例子? 仆人中没有任何东西可以做到这一

result list of map is one longer

This question already has an answer here: Why does map return an additional element when using ranges in Haskell? 1 answer As @duplode suggested, it has to do with how .. behaves with floating point vs. integers: Prelude> let x3 = [1,3..10] :: [Double] Prelude> length x3 6 Prelude> let x3 = [1,3..10] :: [Int] Prelude> length x3 5 Update in response to the comment... A definit

地图的结果列表是一个更长的时间

这个问题在这里已经有了答案: 为什么在Haskell中使用范围时map会返回一个额外的元素? 1个答案 正如@duplode所建议的那样,它与如何..与浮点运算和整数运算相关: Prelude> let x3 = [1,3..10] :: [Double] Prelude> length x3 6 Prelude> let x3 = [1,3..10] :: [Int] Prelude> length x3 5 更新回应评论... 像这样的定义在ghci中: let xs = [1,3..11] 是多态的。 ..是enumFromThenTo函数的快捷方式