Haskell中有类似于以下类型类的东西吗?
class Mergeable (f :: Type -> Type -> Type) where
merge :: f a b -> f c d -> f (a, c) (Either b d)
特别是,假设在某些值和路由上有一个Site类型的索引:
data Site a r
我们希望“合并”两个站点,例如和都将其数据(值)保存在内存中,同时支持路由的或。
instance Mergeable Site where
merge site1 site2 = ...
还有另一种类型,称为RouteEncoder
在范畴理论中,单元可以由两个伴随函子构成。特别是,如果C和D是范畴,F:C --> D和G:D->C是伴随函子,即存在双射。
hom(FX,Y) = hom(X,GY)
对于C中的每个X和D中的Y,则组成G:C->C是一个单模。
一个这样的伴随函子可以通过固定一个类型的b并取F和G来给出。
data F b a = F (a,b)
data G b a = G (b -> a)
instance Functor (F b) where
fmap f (F (a,b)) = F (f a, b)
instance Functor (G b) where
短版本。中的大多数泛型集合都有一个map方法,该方法实际上将返回相同类型的集合。(例如,List[A].map(f:A=>B)返回一个List[B]。)Scala集合库的明确设计就是为了实现这一点。如果我想要编写对任何这样的集合都是多态的代码呢?“映射行为像函子的Traversable”可以表示为类型吗?
Long version. I有一种情况,即有一个抽象表示某种Current类型的对象集合,这样如果这些对象被转换为某种Desired类型,则集合可以使用这些对象来构造某种Result类型的对象。只要使用函数类型,我就可以实现我想要的一切。
(C => D) => R
但是
假设我有这些签名:
module type CharS = sig
type c
type t = BoW | C of c | EoW
val compare : t -> t -> int
val print : Format.formatter -> t -> unit
end
module type GraphemS = sig
type c
type t
val compare : t -> t -> int
val print : Format.formatter -> t -> unit
end
当一个模块试图使用另一个模块时,我遇到了一个问题,但是我得到了一个错误,声称存在签名不匹配,我不知道为什么。不过,我很确定我做得对。下面是一些代码:
module type ITEM =
sig
type item
val leq : item * item -> bool
val initial : item
end
module type HEAP =
sig
type item
type tree
exception InitHeap
val depth : tree -> int
val initHeap : int ->
我想证明
Theorem T20d :forall (x y:R), (0<x /\ 0<y) -> 0 < Rmin x y.
使用
Lemma min_glb_lt n m p : p < n -> p < m -> p < min n m.
它在Coq.Structures.GenericMinMax中
我用Require导入的Coq.Structures.GenericMinMax
但是,当我尝试使用它时,还没有找到"reference min_glb_lt“吗?我怀疑我需要打开一个范围,但我不知道是哪个范围。
在哈斯克尔,什么是最好的方法来消除临时的多民族主义?
在80%的情况下,我不需要fmap在Functor f中具有多态性,实际上我知道我将它应用于哪个实例。用一个特定的实例替换它会给我带来如下结果:
阅读代码时减少大脑推理,更多的是大脑检查。
类型检查器验证时捕获的更多类型错误
什么是最好的方法,例如在范畴理论中,函子F应用于haskell中使用其名称的态射?
-- F is a functor : it maps objects of * to objects of *
data F r = Z | Suc r
-- F is a functor : it maps arr
我在不同的模块中利用了大量的动态参数来实现许多功能。
但是,get-help中不会显示动态参数的.PARAMETER注释块。
.PARAMETER
Some details of the dynamic parameter that is defined in dynamicParam { block}
当通过这样的函数调用get-help cmdlet时,有没有办法向用户提供动态参数详细信息?
谢谢!
在玩包的过程中,我注意到以下类型具有有趣的属性。
> {-# LANGUAGE RankNTypes #-}
> data N f r = N { unN :: forall x. f x -> (x, r) }
是个函子。
> instance Functor (N f) where
> fmap f (N nat) = N $ fmap (fmap f) nat
> -- or, = N $ \fx -> let { (x,a) = nat fx } in (x, f a)
经过几个小时的google/hoogle,我放
我正在使用中的模块,不知道如何推断标准(显示、读取、eq)类型实例以及模块系统。考虑以下代码:
signature USER = sig
type id
type password
val id_read : read id
val pass_read : read password
val id_show : show id
val login : { Id : id, Password : password } -> transaction bool
val whoami : transaction (option id)
en
对于某些类型的F a,Haskell函子T -> a与T -> a有明显的同构关系。
data Pair a = Pair a a -- isomorphic to Bool -> a
data Reader r a = Reader (r -> a) -- isomorphic to r -> a (duh!)
data Identity a = Identity a -- isomorphic to () -> a
data Phantom a = Phantom -- isomorphic to voi
我知道fmap有(a -> b) -> f a -> f b类型,其中f是函子(并且根据函子是什么做不同的事情)。我的基本问题是:给定一些调用fmap r x,ghc如何确定函子f是什么,只考虑到x和r的类型
让我把这个说得更精确点。假设f和f'是函子,对于某些类型的a,f a = f' a,但f b和f' b是不同的。如果r的类型是a -> b,x的类型是f a,那么对于fmap r x,似乎有两种不同的结果:类型为f b的结果和类型为f' b的结果。如何解决这个模棱两可的问题?
第二个问题:我想通过制作一个奇怪的函子来测试这个问题--
结构类似QuickCheck的promote函数的函子的通称是什么,即形式的函数:
promote :: (a -> f b) -> f (a -> b)
(这是flip $ fmap (flip ($)) :: f (a -> b) -> (a -> f b)的反义词)。除了(->) r和Id之外,还有其他有这样操作的函子吗?(我相信一定有)。谷歌的'quickcheck推广‘只是打开了QuickCheck文档,这不会给promote在任何更一般的上下文AFAICS;搜索'quickcheck促销’不会产生任何结果。
我通过Haskell学习了Swift的函数式编程,并发现了这个有趣的概念-- Transducers。一个代码示例实现了一个mapping函数,该函数基本上是一个Transducer,考虑到我们将转换规则作为一个参数传递。
受到启发,我很快把它翻译成了Swift的等价物,这就是我得到的:
func mapping < A, B, C> (f: A -> B) -> ( ( (C,B) -> C) -> ( (C,A) -> C) ) {
return { r in
return { result, a in
在我的应用程序中,我必须动态加载动态链接库。我已经使用DllImport属性动态加载了一个动态链接库。但我得到了以下异常。
System.EntryPointNotFoundException
附加信息:在DLL zkemkeeper.dll‘中找不到名为"Connect_Net“的入口点。
这一例外的可能原因是什么?我该怎么处理这件事。请帮帮我。
以下是我的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImp
在Idris 库中,效果表示为
||| This type is parameterised by:
||| + The return type of the computation.
||| + The input resource.
||| + The computation to run on the resource given the return value.
Effect : Type
Effect = (x : Type) -> Type -> (x -> Type) -> Type
如果我们允许资源为值并交换前两个参数,我们将得到(其余代码在Agda中
在Haskell中,函子类型函子的定义如下(例如,见哈斯克尔维基):
class Functor (f :: * -> *) where
fmap :: (a -> b) -> f a -> f b
据我所知(如果我错了请纠正我),这样的函子只能有一个用类型构造函数(如[]、Maybe等)构造的范畴作为目标范畴。另一方面,人们可能认为函子的任何范畴都是函子的目标,例如所有类型的范畴。例如,Int可以是函子目标类别中的对象,而不仅仅是Maybe Int或[Int]。
Haskell函子受到这种限制的动机是什么?
最后一行我一直得到的错误,未解决的外部。
bool checker(string roman);
// Adds each value of the roman numeral together
int toDecimal(string, bool (function)(string));
int convert(string roman, int i);
int main(){
string roman;
cout << "This program takes a roman numeral the user enters then converts i
我有以下模板专门化,它将C++函数包装到Lua:
template<class ...Args>
struct Wrapper<void (*)(Args...)> {
using F = void (*)(Args...);
static int f (lua_State *L)
{
Lua lua(L);
// Grab the function pointer.
F f = (F) lua_touserdata(L, lua_upvalueindex(1));
// Build
type ('a, 'r) loop
type 'e task
type ('a, 'e) tmpl'
module type COMPONENT =
sig
type t
type event
type r
val update : t -> event -> r
val view : (t, event) tmpl'
end
module type MAIN_COMPONENT =
sig
type t
type event
type r
in