Difference in GHC versions

I was practicing my Haskell and I came across a weird problem which I was unable to find a solution to on the Internet. I decided to solve this problem: https://www.hackerrank.com/challenges/fibonacci-fp In as many ways I can think of. One way is to perform recursion with memoization where I want to use State monad as a cache. I have GHC 7.10.2 on my Windows 10 and GHC 7.6.2 on my Ubuntu 1

GHC版本的差异

我正在练习我的Haskell,遇到了一个奇怪的问题,我无法在Internet上找到解决方案。 我决定解决这个问题: https://www.hackerrank.com/challenges/fibonacci-fp 我能想到的方式有很多种。 一种方法是在memoization中执行递归,我希望使用State monad作为缓存。 我在我的Windows 10上安装了GHC 7.10.2,在我的Ubuntu 14.04上安装了GHC 7.6.2。 下面的代码在7.6.2上编译(并且运行得很好),并且不会在7.10.2上编译,在我

An option to make memoization the default behaviour of Haskell

I have seen all the other memoization tricks and techniques in Haskell but what I am looking for is a straightforward implementation in the level of compiler/interpreter that takes care of memoization for me. For example, consider the following code for the Fibonacci function: fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2) I want some kind of compiler option for ghc (or any other Haskell c

使记忆成为Haskell默认行为的选项

我已经看到了Haskell中所有其他的记忆技巧和技巧,但是我正在寻找的是编译器/解释器级别的简单实现,它为我处理记忆。 例如,考虑斐波那契函数的以下代码: fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2) 我想为ghc(或任何其他Haskell编译器)提供某种编译器选项,默认情况下使用memoization来执行上面的代码。 例如,要计算“fib 10”,首先需要计算“fib 8”和“fib 9”。 而且,计算“fib 9”取决于第一次计算“fib 8”。

How is this fibonacci

By what mechanism is this fibonacci-function memoized? fib = (map fib' [0..] !!) where fib' 1 = 1 fib' 2 = 1 fib' n = fib (n-2) + fib (n-1) And on a related note, why is this version not? fib n = (map fib' [0..] !! n)

这个斐波那契如何?

这种斐波纳契函数是通过什么机制记忆的? fib = (map fib' [0..] !!) where fib' 1 = 1 fib' 2 = 1 fib' n = fib (n-2) + fib (n-1) 并在相关说明,为什么这个版本不是? fib n = (map fib' [0..] !! n)

Rewriting as a practical optimization technique in GHC: Is it really needed?

I was reading the paper authored by Simon Peyton Jones, et al. named “Playing by the Rules: Rewriting as a practical optimization technique in GHC”. In the second section, namely “The basic idea” they write: Consider the familiar map function, that applies a function to each element of a list. Written in Haskell, map looks like this: map f [] = [] map f (x:xs) = f x : map f xs Now supp

在GHC中重写为实用的优化技术:它真的需要吗?

我正在阅读Simon Peyton Jones等人撰写的论文。 名为“按规则演奏:在GHC中重写为实用优化技术”。 在第二部分,即他们写的“基本思想”中: 考虑熟悉的map函数,它将函数应用于列表的每个元素。 用Haskell编写, map如下所示: map f [] = [] map f (x:xs) = f x : map f xs 现在假设编译器遇到以下map调用: map f (map g xs) 我们知道这个表达等同于 map (f . g) xs (其中“。”是函数组合),并且我们知道后者表达

Performance Analysis via Core

The following code runs in about 1.5ms on my computer (compiled with GHC 8.0.1 and -02): import Criterion import Data.Bits import Data.Int import Criterion.Main main :: IO () main = defaultMain [bench "mybench" $ nf (mybench 3840) (0 :: Int)] mybench :: Int -> Int -> Double {-# INLINE mybench #-} mybench n = go 0 n where go s i g | i == 0 = s | otherwise =

通过Core进行性能分析

以下代码在我的计算机上运行约1.5ms(使用GHC 8.0.1和-02编译): import Criterion import Data.Bits import Data.Int import Criterion.Main main :: IO () main = defaultMain [bench "mybench" $ nf (mybench 3840) (0 :: Int)] mybench :: Int -> Int -> Double {-# INLINE mybench #-} mybench n = go 0 n where go s i g | i == 0 = s | otherwise = let (w,_) = f 1 0

Why Haskell ghc does not work, but runghc works well?

One code work from runghc, but I can not compile same one with ghc command. Why? Below is my minimal code and environment: https://gist.github.com/1588756 Works well: $ runghc cat.hs Can not compile: $ ghc cat.hs -o cat Macbook air, max os x snow leopard The .cs extension shown in your paste is wrong;1 rename the file to cat.hs and it'll work fine. This error message: ld: warnin

为什么Haskell ghc不起作用,但runghc运作良好?

一个代码从runghc工作,但我不能用ghc命令编译同一个代码。 为什么? 以下是我最小的代码和环境:https://gist.github.com/1588756 效果很好: $ runghc cat.hs 无法编译: $ ghc cat.hs -o cat Macbook air,max os x雪豹 粘贴中显示的.cs扩展名是错误的; 1将该文件重命名为cat.hs ,它会正常工作。 此错误消息: ld: warning: ignoring file cat.cs, file was built for unsupported file format which is not t

Why does GHC think that this type variable is not injective?

I have this piece of code: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, KindSignatures, GADTs, FlexibleInstances, FlexibleContexts #-} class Monad m => Effect p e r m | p e m -> r where fin :: p e m -> e -> m r data ErrorEff :: * -> (* -> *) -> * where CatchError :: (e -> m a) -> ErrorEff ((e -> m a) -> m a) m instance Monad m => Effect

为什么GHC认为这个类型变量不是内射的?

我有这段代码: {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, KindSignatures, GADTs, FlexibleInstances, FlexibleContexts #-} class Monad m => Effect p e r m | p e m -> r where fin :: p e m -> e -> m r data ErrorEff :: * -> (* -> *) -> * where CatchError :: (e -> m a) -> ErrorEff ((e -> m a) -> m a) m instance Monad m => Effect ErrorEff ((e

Declare a subclass with a complete definition

I am trying to do the following: -- enum which wraps arround class (Enum a, Bounded a) => CyclicEnum a where next, prev :: a -> a -- for equatable types this is readily implemented instance (Enum a, Bounded a, Eq a) => CyclicEnum a where next x | x == maxBound = minBound | otherwise = succ x prev x | x == minBound = maxBound | otherwise = pred

用完整的定义声明一个子类

我正在尝试执行以下操作: -- enum which wraps arround class (Enum a, Bounded a) => CyclicEnum a where next, prev :: a -> a -- for equatable types this is readily implemented instance (Enum a, Bounded a, Eq a) => CyclicEnum a where next x | x == maxBound = minBound | otherwise = succ x prev x | x == minBound = maxBound | otherwise = pred x 但

is Haskell a managed language?

I'm a complete newbie in Haskell. One thing that always bugs me is the ambiguity in whether Haskell is a managed(term borrowed from MS) language like Java or a compile-to-native code like C? The GHC page says this "GHC compiles Haskell code either directly to native code or using LLVM as a back-end". In the case of "compiled to native code", how can features like garb

Haskell是托管语言吗?

我是Haskell的一名完全新手。 有一件事情总是让我感到困惑的是,Haskell是一种托管(从MS借用的术语)语言(如Java)还是像C这样的编译本机代码? GHC页面说这个“GHC直接将Haskell代码编译为本地代码或使用LLVM作为后端”。 在“编译为本地代码”的情况下,垃圾收集等功能如何能够在没有JVM之类的情况下实现? /更新/ 非常感谢你的回答。 从概念上讲,请你帮忙指出我对Haskell垃圾收集的下列理解中的哪一个是正确的: G

List of GHC extensions

I wanted to use {-# LANGUAGE OverloadedStrings #-} but I forgot how it's called. This kind of thing isn't hoogle-able, and also it takes some time finding using google*. Is there somewhere a list of GHC extensions named as they are in the LANGUAGE pragma? * My googling search journey: Google Haskell at wikipedia GHC at wikipedia GHC language features Overload string literal

GHC扩展名列表

我想用{-# LANGUAGE OverloadedStrings #-}但我忘记了它的调用方式。 这种事情不是好事,也需要一些时间来寻找使用谷歌*。 是否在某处存在一个GHC扩展名列表,因为它们在LANGUAGE附注中? *我的谷歌搜索之旅: 谷歌 哈斯克尔在维基百科 GHC在维基百科 GHC语言功能 重载字符串文字 OverloadedStrings 标志参考页面的“语言选项”部分有一个比语言功能页面更容易浏览的列表。 一旦你在那里Ctrl-F搜索“超载”,你