相关疑难解决方法(0)

是否有充分的理由使用unsafePerformIO?

问题就是这一切.更具体地说,我正在编写绑定到C库,我想知道我可以使用哪些c函数unsafePerformIO.我假设使用unsafePerformIO任何涉及指针的东西是一个很大的禁忌.

很高兴看到其他情况也可以使用unsafePerformIO.

haskell

25
推荐指数
4
解决办法
8074
查看次数

得到时间作为国际

haskell中是否有一个函数用于纪元时间,以秒/毫秒为单位?

也许类似于java的东西

System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud)

编辑:as IntInteger

haskell

25
推荐指数
2
解决办法
1万
查看次数

如何从纯函数调用不纯函数?

我刚读完“学到Haskell来造福伟大!”。书,所以我的问题可能很幼稚。我不明白的是如何从纯代码中调用“不纯”的IO函数。

这是一个用C#编写的工作示例。在我们的业务逻辑中,我们根据天气计划一些行动。我们以通常的C#方式进行操作。

interface IWeatherForecast
{
    WeatherData GetWeather(Location location, DateTime timestamp);
}

// concrete implementation reading weather from DB
class DbWeather : IWeatherForecast
{
    public override WeatherData GetWeather(Location location, DateTime timestamp)
    {...}
}

class WeatherFactory
{
    public IWeatherForecast GetWeatherProvider()
    {...}
}

// Business logic independent from any DB
class MaritimeRoutePlanner
{
    private IWeatherForecast weatherProvider = weatherFactory.GetWeatherProvider();

    public bool ShouldAvoidLocation(Location location, DateTime timestamp)
    {
        WeatherData weather = weatherProvider.GetWeather(location, timestamp);
        if(weather.Beaufort > 8)
            return true;
        else...
            ...
    }
}
Run Code Online (Sandbox Code Playgroud)

如何在Haskell中实现此逻辑?

实际上,“纯逻辑” MaritimeRoutePlanner称之为weatherProvider.GetWeather() …

haskell functional-programming

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

标签 统计

haskell ×3

functional-programming ×1