In the Haskell tutorial I'm reading through there is an example that works fine in GHCI (7.10.2) but fails to produce output in a Notebook (both Jupyter, 4.0 or Kronos-Haskell).
The issue seems to involve a function
lockerLookup :: Int -> LockerMap -> Either String Code
which in the tutorial and in GHCI produces a result, for example
ghci> lockerLookup 101 lockers
Right "JAH3I"
in a Notebook gives an error
No instance for (Show (Either String Code)) arising from a use of ‘print’
In a stmt of an interactive GHCi command: print it
Is this the correct behavior in a Notebook? Is there something I can do to produce the expected output in a 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"))
]