Try to upgrade codewars haskell-runner ghc to new version but fail one test.
Code extract from test/runner/haskell_spec.js
This code run fine here but failed on stackage lts-1.0 w/ ghc7.6.3
test.hs:38:12: error:
• Couldn't match type ‘IO ()’ with ‘() -> IO ()’
Expected type: ActionWith ()
Actual type: IO ()
• Possible cause: ‘deleteIfExists’ is applied to too many arguments
In the first argument of ‘after’, namely
‘(deleteIfExists moviesDBFileName)’
In the expression: after (deleteIfExists moviesDBFileName)
In the second argument of ‘($)’, namely
‘after (deleteIfExists moviesDBFileName)
$ do { it "contains the movies we expect"
$ do { mkMoviesDB;
movies <- getMovies;
.... } }’
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies #-}
{-# LANGUAGE OverloadedStrings, GADTs, FlexibleContexts, MultiParamTypeClasses #-}
{-# LANGUAGE NoMonomorphismRestriction, GeneralizedNewtypeDeriving #-}
module Movies where
import Database.Persist (insertMany)
import Database.Persist.Sqlite (runSqlite, runMigration)
import Database.Persist.TH (mkPersist, mkMigrate, persistUpperCase, share, sqlSettings)
share [mkPersist sqlSettings, mkMigrate "migrateTables"] [persistUpperCase|
Movies
title String
year Int
rating Int
deriving Eq Show
|]
mkMoviesDB :: IO ()
mkMoviesDB = runSqlite "/tmp/movies.db" $ do
runMigration migrateTables
insertMany
[ Movies "Rise of the Planet of the Apes" 2011 77
, Movies "Dawn of the Planet of the Apes" 2014 91
, Movies "Alien" 1979 97
, Movies "Aliens" 1986 98
, Movies "Mad Max" 1979 95
, Movies "Mad Max 2: The Road Warrior" 1981 100
]
return ()
{-# LANGUAGE QuasiQuotes, TemplateHaskell, TypeFamilies #-}
{-# LANGUAGE OverloadedStrings, GADTs, FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
import Test.Hspec
import Database.Persist
import Control.Monad.IO.Class (MonadIO(liftIO))
import Database.Persist.Sqlite (runSqlite)
import Database.Persist.Sql (rawQuery)
import Data.Conduit (($$), (=$))
import Data.Conduit.List as CL
import Data.Text (pack, unpack)
import Movies (mkMoviesDB)
import Control.Monad (when)
import System.Posix.Files (fileExist)
import System.Directory (removeFile)
data Movie = Movie String Integer Integer deriving (Eq, Show)
moviesDBFileName :: String
moviesDBFileName = "/tmp/movies.db"
getMovies :: IO [Movie]
getMovies = runSqlite (pack moviesDBFileName) $ do
rawQuery "select Title, Year, Rating from Movies" [] $$ CL.map toMovie =$ consume
where
toMovie [PersistText title, PersistInt64 year, PersistInt64 rating] =
Movie (unpack title) (toInteger year) (toInteger rating)
deleteIfExists :: String -> IO ()
deleteIfExists fileName = do
exists <- fileExist fileName
when exists $ removeFile fileName
main :: IO ()
main = hspec $ do
describe "/tmp/movies.db"
$ before (deleteIfExists moviesDBFileName)
$ after (deleteIfExists moviesDBFileName)
$ do
it "contains the movies we expect" $ do
mkMoviesDB
movies <- getMovies
liftIO $ movies `shouldBe` [ Movie "Rise of the Planet of the Apes" 2011 77
, Movie "Dawn of the Planet of the Apes" 2014 91
, Movie "Alien" 1979 97,Movie "Aliens" 1986 98
, Movie "Mad Max" 1979 95
, Movie "Mad Max 2: The Road Warrior" 1981 100]