我想了解更多关于函数式编程,使用language.ext(C#)库作为起点。我正在尝试使用任一monad,但有一些我错过了。见一个简单的例子:开始与language.ext(功能C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dates
{
public class AssignmentDate
{
public static Either<string, AssignmentDate> Create(DateTime date)
{
if (date < MinValue)
return Left<string, AssignmentDate>("date out of range");
return Right<string, AssignmentDate>(date);
}
public static DateTime MinValue => new DateTime(1950, 1, 1);
}
}
左<类型>和右<>无法解析。我明显错过了一些东西,但是什么?我正确使用<>吗?这是使用Either <>时返回的正确方法吗?任何人都可以指向language.ext的更多例子吗?非常感谢您提供的任何帮助。
您需要导入包含的名称空间,并使用'new Left <...>'和新的Right <...>'。 – Lee
感谢您回答李 - 通常Visual Studio是足够好找到这一点,但通过LanguageExt.Core包看,我找不到Left <>和Right <>(我期望找到与Either <>相同的命名空间) 。这让我觉得我误解了一些根本性的东西 - 因此是一个问题。 –
我发现我错过了 - “使用静态LanguageExt.Prelude;”这解决了事情正确。奇怪的是,Visual Studio的行为与此不同(并且我无法通过对象浏览器找到任何东西)。谢谢你的帮助。 –