小编jac*_*ckb的帖子

Java中的函数

我正在尝试在Java中定义类似于Haskell的仿函数的类.因此,仿函数定义为:

/**
 * Programming languages allow only (just simply enough) endofunctor, that are functors from and to the same category.
 * In this case, the category is the one of the datatypes (in here Type, in order to make it more clear)
 */
public interface EndoFunctor<X extends Type> extends Type {

    /**
     * The basic implementation for any element fx
     * @param map   Transformation function for the type parameter
     * @param fx    Element of the current class
     * @param <Y> …
Run Code Online (Sandbox Code Playgroud)

java haskell category-theory

6
推荐指数
2
解决办法
378
查看次数

Haskell类型参数类型

我想定义一个特定的仿函数如下:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}

data ValOrError a b = Val a | Error b

class MF c a b where
  mcons :: a -> c -> c
  merr :: b -> c
  mhead :: c -> ValOrError a b
  mtail :: c -> ValOrError c b
Run Code Online (Sandbox Code Playgroud)

我希望我的类型MF上的类型类型c具有类型参数ab.我试着在这样的数据结构上定义一个过滤函数,如下所示:

mfilter f e =
  let h = mhead e in
  let t = mtail e in
  case h of
    Error …
Run Code Online (Sandbox Code Playgroud)

haskell abstraction interface typeclass

3
推荐指数
1
解决办法
85
查看次数