English 中文(简体)
在Haskell使用OOP方法等功能
原标题:Using function like OOP method in Haskell

我正在研究Haskell这些日子,并采用OOP方法等功能。

第一,将经营者定义为:

(//) :: a -> (a -> b) -> b
x // f = f x

如你所知,该运营商将职能顺序改为<条码>f,然后适用<条码>。 例如,<代码>等于 可定义为:

equals :: Eq a => a -> a -> Bool
equals = x -> y -> x == y

comparison = (1 + 2) // equals 3 -- True

现在,我的问题是。 <> 是否使用Haskell功能,如OOP方法? 这意味着职能转移,(首先)论点是好还是坏的。

<>>>>>

Here is the case of backtick(`) is not available.

data Person = Person { name :: String }
myself = Person "leafriend"

之后

> name myself
"leafriend"
> myself // name
"lefirend"
> myself `name`
ERROR - Syntax error in expression (unexpected end of input)
最佳回答

你所写的只是一种风格。 (C/Java方案制定者使用/作为经营人,尽管如此,似乎非常残酷。) 由于以下几个原因,我不鼓励采用这一方法:

  • It s not idiomatic Haskell, and will confuse any Haskellers trying to read your code
  • You shouldn t think of Haskell as you would think of an OOP language

如果你再次试图使Haskell比你喜欢的OOP语言更像,那么你就错了。 Haskell的用意是看像数学:有预设功能的液化物,但也有固定功能和操作者。

问题回答

暂无回答




相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签