如何在IO函数中使用纯函数?: - /
例如:我正在读取一个文件(IO函数),我想通过使用具有引用透明性的纯函数来解析其上下文,一个字符串.
似乎这样的世界,纯函数和IO函数是分开的.我怎么可能桥接他们?
我正在Haskell编写一个AI General Problem Solver,用于Coursera的AI Planning课程,ghci抱怨一个模糊的类型变量.这是Haskell代码和我得到的错误:
-- Solver.hs
{-# LANGUAGE GADTs,FlexibleInstances,UndecidableInstances,ScopedTypeVariables,TypeFamilies,MultiParamTypeClasses #-}
module Solver
(Solver,State,Transition)
where
class (Show t,Eq t) => Transition t where
transition :: State s => s -> t -> s
class (Show s,Eq s) => State s where
getPossibleTransitions :: Transition t => s -> [t]
isStateValid :: s -> Bool
isGoalState :: s -> Bool
class Solver s t where
getPossibleNextStates :: s -> [s]
isStateVisited :: [s] -> s -> Bool
getNextFringeStates :: [s] -> …
Run Code Online (Sandbox Code Playgroud) Haskell和Regex - 为什么我的函数不能消除RedundantSpaces的工作?
import Text.Regex
eliminateRedundantSpaces text =
subRegex (mkRegex "\\s+") text " "
Run Code Online (Sandbox Code Playgroud)