问题就是这一切.更具体地说,我正在编写绑定到C库,我想知道我可以使用哪些c函数unsafePerformIO.我假设使用unsafePerformIO任何涉及指针的东西是一个很大的禁忌.
很高兴看到其他情况也可以使用unsafePerformIO.
haskell中是否有一个函数用于纪元时间,以秒/毫秒为单位?
也许类似于java的东西
System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud)
编辑:as Int或Integer?
我刚读完“学到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() …