Haskell代码无法在Notebook中显示输出

时间:2015-08-18 15:40:40

标签: haskell ipython-notebook jupyter

Haskell tutorial我阅读时,有一个例子在GHCI(7.10.2)中工作正常,但无法在Notebook(Jupyter,4.0或Kronos-Haskell)中产生输出。

这个问题似乎涉及一个功能

lockerLookup :: Int -> LockerMap -> Either String Code

在教程和GHCI中产生结果,例如

ghci> lockerLookup 101 lockers  
Right "JAH3I"
笔记本中的

发出错误

No instance for (Show (Either String Code)) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it

这是笔记本中的正确行为吗?我能做些什么来在Notebook中产生预期的输出吗?

import qualified Data.Map as Map    

data LockerState = Taken | Free deriving (Show, Eq)    
type Code = String    
type LockerMap = Map.Map Int (LockerState, Code) 

lockerLookup :: Int -> LockerMap -> Either String Code  
lockerLookup lockerNumber lockerMap =   
    case Map.lookup lockerNumber lockerMap of   
        Nothing -> Left $ "Locker number " ++ show lockerNumber ++ " doesn't exist!"  
        Just (state, code) -> if state /= Taken
            then Right code
            else Left $ "Locker " ++ show lockerNumber ++ " is already taken!"

lockers :: LockerMap  
lockers = Map.fromList   
    [(100,(Taken,"ZD39I"))  
    ,(101,(Free,"JAH3I"))  
    ,(103,(Free,"IQSA9"))  
    ,(105,(Free,"QOTSA"))  
    ,(109,(Taken,"893JJ"))  
    ,(110,(Taken,"99292"))  
    ]  

1 个答案:

答案 0 :(得分:3)

如果您使用的是Haskell平台,请确保目录

~/Library/Haskell/bin

存在并在您的路径中 /usr/bin之前显示

平台安装新二进制文件的位置,因此您需要使用PATH来访问您构建的应用程序,并使用平台附带的升级版工具(例如cabal,happy,alex,等)

此外,您可以使用这些说明自行安装IHaskell:

https://github.com/gibiansky/IHaskell#install-haskell-tools