Possible Duplicate: Small Haskell program compiled with GHC into huge binary Recently I noticed how large Haskell executables are. Everything below was compiled on GHC 7.4.1 with -O2 on Linux. Hello World ( main = putStrLn "Hello World!" ) is over 800 KiB. Running strip over it reduces the filesize to 500 KiB; even adding -dynamic to the compilation doesn't help much, leavi
可能重复: 用GHC编译成的小Haskell程序变成了巨大的二进制文件 最近我注意到Haskell可执行文件的大小。 下面的所有内容都是在GHC 7.4.1上用Linux上的-O2编译的。 Hello World( main = putStrLn "Hello World!" )超过800 KiB。 在其上运行strip可将文件大小减少到500 KiB; 即使在编译时添加-dynamic编译也没有什么帮助,只剩下大约400 KiB的可执行文件。 编译一个涉及Parsec的非常原始的例子会产生一个1.
Hey, I'm learning Haskell and I'm interested in using it to make static libraries for using in Python and probably C. After some googling I found out how to get GHC to output a shared object, but it dynamically depends on GHC`s libraries. The resulting ELF from compiling in GHC is dynamically dependand only on C libs and it's a bit under a MB in size - it has been statically linked w
嘿,我正在学习Haskell,我有兴趣使用它来创建静态库,以便在Python和C中使用。经过一些Google搜索后,我发现如何让GHC输出共享对象,但它动态依赖于GHC s的图书馆。 在GHC中编译生成的ELF只能动态地依赖于C库,并且它的大小略低于MB - 它已经与GHC的libs静态链接。 如何以及如果这可以实现共享对象? 当前状态示例: $ ghc --make -dynamic -shared -fPIC foo.hs -o libfoo.so $ ldd libfoo.so linux-vdso.so.1 =>
stack ghc -- --version The Glorious Glasgow Haskell Compilation System, version 7.10.3 I want to upgrade to ghc 8. How can I tell stack to upgrade ghc? dysfun from the IRC answered my question so I will post it here for more posterity. To update the ghc used to compile a project, go to the yaml file. In there is the resolver field. Update that accordingly. For my case, I found this
堆栈ghc - --version Glorious Glasgow Haskell编译系统,版本7.10.3 我想升级到ghc 8。 我怎样才能告诉栈来升级ghc? 来自IRC的dysfun回答了我的问题,所以我会在此发布更多后代。 要更新用于编译项目的ghc,请转至yaml文件。 有解析器字段。 相应地更新。 对于我的情况,我发现这个网页https://www.stackage.org/lts-9.0
In Haskell, monads are defined in terms of the functions return and bind, where return has type a -> ma and bind has type ma -> (a -> mb) -> mb . It's been pointed out before that monads can also be defined in terms of return and join, where join is a function with type m (ma) -> ma . Bind can be defined in terms of join, but is the reverse possible? Can join be defined in t
在Haskell中,monads是根据函数return和bind定义的,其中return的类型a -> ma ,bind的类型为ma -> (a -> mb) -> mb 。 之前已经指出单子也可以用返回和连接来定义,其中连接是类型为m (ma) -> ma的函数。 绑定可以根据连接来定义,但是可能相反吗? 可以根据绑定来定义连接吗? 如果没有加入,我不知道如果我以某种方式获得了“两次包裹”一元值, m (ma) - 没有任何函子或monad操作“删除任何图层”,我会做什
In Scalaz every Monad instance is automatically an instance of Applicative . implicit val listInstance = new Monad[List] { def point[A](a: => A) = List(a) def bind[A, B](fa: List[A])(f: A => List[B]) = fa flatMap f } List(2) <*> List((x: Int) => x + 1) // Works! Another example: Arrow is automatically a Profunctor . However, in Haskell I must provide an instance of Applica
在Scalaz中,每个Monad实例都自动成为Applicative一个实例。 implicit val listInstance = new Monad[List] { def point[A](a: => A) = List(a) def bind[A, B](fa: List[A])(f: A => List[B]) = fa flatMap f } List(2) <*> List((x: Int) => x + 1) // Works! 另一个例子: Arrow自动是一个Profunctor 。 但是,在Haskell中,我必须一次又一次地为每个Monad提供一个Applicative实例。 是否有可能避
As described this question/answers, Functor instances are uniquely determined, if they exists. For lists, there are two well know Applicative instances: [] and ZipList . So Applicative isn't unique (see also Can GHC derive Functor and Applicative instances for a monad transformer? and Why is there no -XDeriveApplicative extension?). However, ZipList needs infinite lists, as its pure repea
如所描述的这个问题/答案, Functor实例是唯一确定的,如果它们存在的话。 对于列表,有两个众所周知的Applicative实例: []和ZipList 。 因此, Applicative不是唯一的 (另请参阅GHC可以派生函子和适用于monad变换器的实例吗?为什么没有-XDeriveApplicative扩展?)。 然而, ZipList需要无限列表,因为它的pure无限期地重复给定的元素。 还有其他更好的数据结构示例,它们至少有两个Applicative实例? 是否有这样的
I'm trying to implement MaybeT in the spirit of the mtl library. With this non-compiling solution: {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} import Control.Monad import Control.Monad.Trans import Control.Monad.State newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } instance (Monad m) => Monad (MaybeT m) where x >>= f = MaybeT $ ru
我试图以mtl库的精神实现MaybeT 。 有了这个非编译解决方案: {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} import Control.Monad import Control.Monad.Trans import Control.Monad.State newtype MaybeT m a = MaybeT { runMaybeT :: m (Maybe a) } instance (Monad m) => Monad (MaybeT m) where x >>= f = MaybeT $ runMaybeT x >>= maybe (return Nothing) (r
After reading (and skimming some sections of) Wadler's paper on monads, I decided to work through the paper more closely, defining functor and applicative instances for each of the monads he describes. Using the type synonym type M a = State -> (a, State) type State = Int Wadler uses to define the state monad, I have the following (using related names so I can define them with a newtype
在阅读Wadler关于monad的论文(并略读了部分内容)之后,我决定更仔细地研读论文,为他描述的每个monad定义仿函数和应用实例。 使用类型同义词 type M a = State -> (a, State) type State = Int Wadler用来定义状态monad,我有以下(使用相关的名称,以便我可以在稍后用newtype声明来定义它们)。 fmap' :: (a -> b) -> M a -> M b fmap' f m = st -> let (a, s) = m st in (f a, s) pure' :: a -> M a p
Haskell newbie here. $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 While trying to debug weird locale-related bug in third-party Haskell program, I'm trying to print default encoding: import System.IO main = do print localeEncoding But it fails: $ ghc -o printlocale main.hs main.hs:4:2: No instance for (Show TextEncoding) arising from a use
Haskell新手在这里。 $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.1 当试图在第三方Haskell程序中调试与奇怪的语言环境相关的错误时,我试图打印默认编码: import System.IO main = do print localeEncoding 但它失败了: $ ghc -o printlocale main.hs main.hs:4:2: No instance for (Show TextEncoding) arising from a use of `print' at main.hs:4:2-21 Possibl
In the vinyl library, there is a RecAll type family, which let's us ask that a partially applied constraint is true for every type in a type level list. For example, we can write this: myShowFunc :: RecAll f rs Show => Rec f rs -> String And that's all lovely. Now, if we have the constraint RecAll f rs c where c is unknown, and we know the cx entails dx (to borrow language from
在乙烯基库中,有一个RecAll类型的家族,让我们要求对于类型级别列表中的每个类型,部分应用的约束条件是真实的。 例如,我们可以这样写: myShowFunc :: RecAll f rs Show => Rec f rs -> String 这一切都很可爱。 现在,如果我们有约束RecAll f rs c ,其中c未知,并且我们知道cx需要dx (从ekmett的contstraints包中借用语言),那么我们如何才能获得RecAll f rs d ? 我问的原因是我正在处理一些需要满足几个类