Haskell + 持续存在:解析错误可能是缩进不正确或括号不匹配
Haskell + Persistent: parse error possibly incorrect indentation or mismatched brackets
我在过去几个月里一直在学习 Haskell 并且正在努力按照本教程学习 Haskell + Persistent:
https://www.yesodweb.com/book/persistent#persistent_code_generation
module Main where
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
import Control.Monad.IO.Class (liftIO)
mkPersist sqlSettings [persistLowerCase|
Person
name String
age Int
deriving Show
|]
我以前没有遇到过这种语法(他们在教程中谈论 'QuasiQuotes' 所以我猜这就是它),但我认为我直接从教程中获取了代码它应该编译。但是,它不会,我收到以下错误:
/home/will/programming/learn-haskell/postgres-example/app/Main.hs:15:1: error:
parse error (possibly incorrect indentation or mismatched brackets)
|
15 | Person
| ^
-- While building package postgres-example-0.1.0.0 using:
/home/will/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0 build exe:simple --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
这是我的 cabal 文件中的配置:
name: postgres-example
version: 0.1.0.0
synopsis: An example of using Haskell and PostGres with persistent
description: Please see README.md
license: BSD3
license-file: LICENSE
author: Will Taylor
copyright: 2020, Will Taylor
category: Web
build-type: Simple
cabal-version: >=1.10
executable simple
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, persistent
, persistent-template
, persistent-postgresql
, monad-logger
default-language: Haskell2010
如果有人能帮助我,那就太好了。
我也是Haskell的初学者。按照相同的文档,我试图将架构定义移动到另一个模块并将其导入 main.它根本无法使用相同的错误消息。
在各处尝试 copy/pasting 代码并使用 postgres 测试 2-3 小时后,我在这个过程中意识到了一些事情。在文档中,包含语言功能的注释先于其他内容出现在文件顶部。
只需将评论移至顶部即可
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Sql.Schema where
import Database.Persist
import Database.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
firstName String
lastName String
age Int Maybe
PersonName firstName lastName
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
|]
我在过去几个月里一直在学习 Haskell 并且正在努力按照本教程学习 Haskell + Persistent:
https://www.yesodweb.com/book/persistent#persistent_code_generation
module Main where
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
import Control.Monad.IO.Class (liftIO)
mkPersist sqlSettings [persistLowerCase|
Person
name String
age Int
deriving Show
|]
我以前没有遇到过这种语法(他们在教程中谈论 'QuasiQuotes' 所以我猜这就是它),但我认为我直接从教程中获取了代码它应该编译。但是,它不会,我收到以下错误:
/home/will/programming/learn-haskell/postgres-example/app/Main.hs:15:1: error:
parse error (possibly incorrect indentation or mismatched brackets)
|
15 | Person
| ^
-- While building package postgres-example-0.1.0.0 using:
/home/will/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0 build exe:simple --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
这是我的 cabal 文件中的配置:
name: postgres-example
version: 0.1.0.0
synopsis: An example of using Haskell and PostGres with persistent
description: Please see README.md
license: BSD3
license-file: LICENSE
author: Will Taylor
copyright: 2020, Will Taylor
category: Web
build-type: Simple
cabal-version: >=1.10
executable simple
hs-source-dirs: app
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, persistent
, persistent-template
, persistent-postgresql
, monad-logger
default-language: Haskell2010
如果有人能帮助我,那就太好了。
我也是Haskell的初学者。按照相同的文档,我试图将架构定义移动到另一个模块并将其导入 main.它根本无法使用相同的错误消息。
在各处尝试 copy/pasting 代码并使用 postgres 测试 2-3 小时后,我在这个过程中意识到了一些事情。在文档中,包含语言功能的注释先于其他内容出现在文件顶部。
只需将评论移至顶部即可
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Sql.Schema where
import Database.Persist
import Database.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Person
firstName String
lastName String
age Int Maybe
PersonName firstName lastName
deriving Show
BlogPost
title String
authorId PersonId
deriving Show
|]