strict functions (semantics)?

According to this article on denotational semantics in haskell All types have bottom, and a function f:A->B is strict if it maps the bottom of type A to the bottom of type B, it is called non-strict other-wise. (This is reminiscent of a pointed category where morphisms preserve the basepoint). Why does Haskell have non-strict functions, whereas Standard ML doesn't? Every programming

严格的函数(语义)?

根据这篇关于haskell中的指称语义的文章,所有类型都有底部,并且函数f:A-> B将A类底部映射到B类底部时是严格的,因此它被称为非严格。 (这让人联想到态射保持基点的尖端类别)。 为什么Haskell具有非严格的功能,而标准ML没有? 每种递归编程语言都至少有一个非严格函数,通常以条件形式( if-then-else )形式存在。 否则,所有的递归都会表示底部(非终止)。 尽管非严格功能是必不可少的,但是,大多数这些语言

In Haskell, why non

This is a follow-up of Why am I getting "Non-exhaustive patterns in function..." when I invoke my Haskell substring function? I understand that using -Wall , GHC can warn against non-exhaustive patterns. I'm wondering what's the reason behind not making it a compile-time error by default given that it's always possible to explicitly define a partial function: f :: [a] -&

在Haskell中,为什么不是

这是我为什么在调用Haskell子字符串函数时得到“函数中的非穷举模式”的后续行为? 据我所知,使用-Wall ,GHC可以对非详尽的模式提出警告。 我想知道是什么原因导致默认情况下没有编译时错误,因为总是可以显式定义一个部分函数: f :: [a] -> [b] -> Int f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length xs + length ys 这个问题不是GHC特有的。

XAllowAmbiguousTypes appropriate?

I've recently posted a question about syntactic-2.0 regarding the definition of share . I've had this working in GHC 7.6 : {-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-} import Data.Syntactic import Data.Syntactic.Sugar.BindingT data Let a where Let :: Let (a :-> (a -> b) :-> Full b) share :: (Let :<: sup, sup ~ Domain b, sup ~ Domain a, S

XAllowAmbiguousTypes是否合适?

我最近发布了一个关于语法-2.0关于share定义的问题。 我已经在GHC 7.6中工作过了: {-# LANGUAGE GADTs, TypeOperators, FlexibleContexts #-} import Data.Syntactic import Data.Syntactic.Sugar.BindingT data Let a where Let :: Let (a :-> (a -> b) :-> Full b) share :: (Let :<: sup, sup ~ Domain b, sup ~ Domain a, Syntactic a, Syntactic b, Syntactic (a ->

Is there something better than unsafePerformIO for this....?

I've so far avoided ever needing unsafePerformIO , but this might have to change today.... I would like to see if the community agrees, or if someone has a better solution. I have a library which needs to use some config data stored in a bunch of files. This data is guaranteed static (during the run), but needs to be in files that can (on very rare occasions) be edited by an end user who c

有没有什么比unsafePerformIO更适合这个....?

到目前为止,我避免需要unsafePerformIO ,但今天可能不得不改变......我想看看社区是否同意,或者如果有人有更好的解决方案。 我有一个库需要使用存储在一堆文件中的一些配置数据。 这些数据保证是静态的(在运行过程中),但需要在可以(在极少数情况下)由不能编译Haskell程序的最终用户编辑的文件中。 (细节是不重要的,但将“/etc/mime.types”视为一个相当不错的近似值,它是一个在很多程序中使用的大型静态数据文件)

is GHC's implementation of Haskell semantically broken?

I noticed something interesting this morning that I wanted to ask about to see if it is in anyway significant. So in Haskell, undefined Semantically subsumes non-termination. So it should be impossible to have a function isUndefined :: a -> Bool as the semantics would indicate that this solves the halting problem. However I believe that some of GHC's built in functions allow this re

是GHC的Haskell语义破坏的实现?

今天早上我注意到一些有趣的事情,我想问一下看看它是否有意义。 所以在Haskell中,未定义的语义上包含非终止。 所以应该不可能有一个功能 isUndefined :: a -> Bool 因为语义会表明这解决了暂停问题。 不过,我相信GHC的一些内置功能允许这种限制“相当可靠”地被打破。 特别抓住#。 以下代码允许未定义的值被“相当可靠地”检测到: import Control.Exception import System.IO.Unsafe import Unsafe.Coerce isUnde

cmm call format for foreign primop (integer

I have been checking out integer-gmp source code to understand how foreign primops can be implemented in terms of cmm as documented on GHC Primops page. I am aware of techniques to implement them using llvm hack or fvia-C/gcc - this is more of a learning experience for me to understand this third approach that interger-gmp library uses. So, I looked up CMM tutorial on MSFT page (pdf link), wen

cmm调用格式为外国primop(整数

我一直在检查integer-gmp源代码,以了解如何根据GHC Primops页面上记录的cmm方式实现外国的primops。 我知道使用llvm hack或fvia-C / gcc来实现它们的技术 - 这对我来说更加了解interger-gmp库使用的第三种方法。 因此,我在MSFT页面上查找了CMM教程(pdf链接),通过了GHC CMM页面,仍然有一些未解答的问题(难以将所有这些概念放在头脑中,而不深入CMM,这正是我现在所做的)。 有这个代码片段从整数bmp cmm文件: integer

GHC code generation for type class function calls

In Haskell to define an instance of a type class you need to supply a dictionary of functions required by the type class. Ie to define an instance of Bounded , you need to supply a definition for minBound and maxBound . For the purpose of this question, let's call this dictionary the vtbl for the type class instance. Let me know if this is poor analogy. My question centers around what k

用于类型函数调用的GHC代码生成

在Haskell中定义一个类型类的实例,你需要提供一个类型类所需的函数字典。 即定义Bounded的实例,您需要提供minBound和maxBound的定义。 为了这个问题的目的,我们把这个字典作为类型实例的vtbl 。 让我知道这是否可怜类比。 我的问题主要集中在我调用类类函数时可以从GHC得到什么样的代码生成。 在这种情况下,我看到三种可能性: 在运行时查找实现函数的vtbl查找已关闭 vtbl查找是在编译时完成的,并且在生成的代码

Pivot Quicksort in Haskell

Is it possible to implement a quicksort in Haskell (with RANDOM-PIVOT) that still has a simple Ord a => [a]->[a] signature? I'm starting to understand Monads, and, for now, I'm kind of interpreting monads as somethink like a 'command pattern', which works great for IO. So, I understand that a function that returns a random number should actually return a monadic value li

Haskell中的枢轴Quicksort

是否有可能在Haskell中实现快速排序(使用RANDOM-PIVOT),它仍然有一个简单的Ord a => [a]->[a]签名? 我开始理解Monads,而现在,我有点像单片机那样思考单子,这对于IO来说非常有用。 所以,我明白一个返回一个随机数的函数实际上应该返回一个像IO这样的monadic值,否则它会破坏引用透明性。 我也明白,应该没有办法从返回的monadic值中“提取”随机整数,否则,它会再次破坏参考透明度。 但是,我仍然认为应该可

In what sense is the IO Monad pure?

I've had the IO monad described to me as a State monad where the state is "the real world". The proponents of this approach to IO argue that this makes IO operations pure, as in referentially transparent. Why is that? From my perspective it appears that code inside the IO monad have plenty of observable side effects. Also, isn't it possible to describe pretty much any non-pu

IO Monad纯粹是什么意思?

我曾将IO monad描述为国家单体,其中国家是“真实的世界”。 这种IO方法的支持者认为,这使得IO操作是纯粹的,就像在透明方面一样。 这是为什么? 从我的角度来看,IO monad中的代码有很多可观察到的副作用。 另外,难道不能像真实世界的函数那样描述任何非纯函数吗? 例如,我们不能把C的malloc想象成一个函数,它需要一个RealWorld和一个Int并且返回一个指针和一个RealWorld,就像RealWorld隐含的IO monad一样? 注意:我

Mixing Erlang and Haskell

If you've bought into the functional programming paradigm, the chances are that you like both Erlang and Haskell. Both have purely functional cores and other goodness such as lightweight threads that make them a good fit for a multicore world. But there are some differences too. Erlang is a commercially proven fault-tolerant language with a mature distribution model. It has a seemingly u

混合Erlang和Haskell

如果你已经购买了函数式编程范例,那么你很可能喜欢Erlang和Haskell。 两者都具有纯粹的功能内核和其他优点,例如轻量级线程,使其非常适合多核世界。 但也有一些不同之处。 Erlang是经过商业验证的具有成熟分布模型的容错语言。 它具有看似独特的功能,能够通过热代码加载在运行时升级其版本。 (很酷!) 另一方面,Haskell具有任何主流语言中最复杂的类型系统。 (我将'主流'定义为任何具有已发表的O'Re