Quick Start
Haskell是一个比较偏的语言,但是对于理解函数式编程很有帮助,在日后使用其他函数式语言会有所帮助,比如说sacla语言。下面做一个Yesod Framework的教程。
Yesod是y一个Haskell的Web框架。
运行环境
基于haskell进行构建。
Follow the haskell-lang get started guide to get the Stack build tool.
On POSIX systems, this is usually
1
curl -sSL https://get.haskellstack.org/ | sh
Create a new scaffolded site:
1
stack new my-project yesod-sqlite && cd my-project
NOTE: Use stack templates to see other available Yesod scaffoldings.
Install the yesod command line tool:
1
stack install yesod-bin --install-ghc
Build libraries:
1
stack build
Launch devel server:
1
stack exec -- yesod devel
View your Yesod site at http://localhost:3000/
Add Handler
1
stack exec -- yesod add-handler
Hello World
这里我们编写一个Hello World的实例介绍
- 在templeates目录下创建一个文件hello.hamlet。
这是一个页面文件,相当于动态web语言中的页面,需要注意的是,在这里不需要写结尾标签。(搞不懂这个设计有啥好处)
1 | <div .ui.container> |
- 修改路由文件config/routes
<请求路径> <控制层> <请求类型>
1 | /hello HelloR GET |
- 编写控制层src/Handler/Hello.hs
1 |
|
访问测试
1 | stack exec -- yesod devel |
打开浏览器:http://localhost:3000/hello
其他
More info: 官网