在Haskell中,有没有infinity :: Num a =>一个? [英] In Haskell, is there infinity :: Num a => a?

查看:93
本文介绍了在Haskell中,有没有infinity :: Num a =>一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实现一个数据结构,如果我使用无穷大来进行数值比较,那么它就会非常简单。注意,这不是maxBound / minBound,因为一个值可以是<=最大值,但所有值都是<无穷无尽。

I'm trying to implement a data structure where if I had the use of infinity for numerical comparison purposes, it would simply things greatly. Note this isn't maxBound/minBound, because a value can be <= maxbound, but all values would be < infinity.

没有希望?

No hope?

推荐答案

类型?

data Infinite a = Infinite | Only a

然后为Num a => Infinite a写一个Num实例,并且需要数字规则。

then write a Num instance for Num a => Infinite a, with the numeric rules you need.

这篇关于在Haskell中,有没有infinity :: Num a =&gt;一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆