• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

joshcough/HaskellStarter: A project that demonstrates getting up and running wit ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

joshcough/HaskellStarter

开源软件地址(OpenSource Url):

https://github.com/joshcough/HaskellStarter

开源编程语言(OpenSource Language):

Haskell 78.4%

开源软件介绍(OpenSource Introduction):

HaskellStarter Build Status

This project demonstrates how to set up your own real Haskell project, and helps you get a feel for the Haskell ecosystem. Currently, teaching Haskell is not a goal of this project, but it may in the future. As for now, basic knowledge of Haskell is assumed, and this project is aimed at people who want to build a real program or library in Haskell.

Getting started with this project

The best way to get started with this project is to simply clone it, and poke around.

git clone https://github.com/joshcough/HaskellStarter.git

Here are the contents of the project:

$ tree -a -I .git
.
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── Setup.hs
├── executables
│   └── Main.hs
├── haskell-starter.cabal
├── src
│   └── HaskellStarter
│       ├── CommitPrinter.hs
│       └── Util.hs
├── test
│   ├── DocTest.hs
│   ├── Main.hs
│   ├── Properties.hs
│   └── UnitTests.hs
└── travis
    ├── cabal-apt-install
    └── config

5 directories, 15 files

Some valuable commands to play with (all of which will be explained) are:

$ cabal --help
$ cabal update
$ cabal init
$ cabal install github
$ cabal build
$ cabal test
$ cabal repl
$ cabal install

Prerequisites

As stated, this project assumes some basic knowledge of Haskell. If you don't have that, I recommend Learn You a Haskell for Great Good!. Also, if you haven't already, go install the Haskell Platform.

ghci

In order to have some basic knowledge of Haskell, it's highly likely that you've played with ghci, but a refresher still helps.

ghci is a simple way to get started playing with Haskell, and is essential for testing out functions and types during development.

Run ghci at the command line by simply typing ghci:

$ ghci

Input expressions

prelude> 5 + 5
10
prelude> let x = 10
prelude> x + x
20

Get types with :t

prelude> :t x
x :: Num a => a
prelude> let x = 7 :: Int
prelude> :t x + x
x + x :: Int

Load files with :load

prelude> :load Goop
*Goop> --now run some expressions in Goop

Quit ghci

prelude> ^d

Hoogle

Hoogle is the go to place for finding:

  • Functions
  • Libraries
  • Documentation
  • Links to source code
  • etc...

Maybe we want to write a library that does some fun stuff with the Github API (http://developer.github.com/v3/). Let's go search Hoogle to see if there is anything already there to help us:

https://lmddgtfy.net/?q=!hoogle%20github

Yay, we've discovered a Github package — http://hackage.haskell.org/package/github, complete with everything listed above. Poke around and find out more. After you're done poking, you should install the package:

$ cabal install github

Cabal

While ghci is useful for playing with Haskell code, it doesn't enable you to build libraries and programs. Cabal (Common Architecture for Building Applications and Libraries) is installed with the Haskell Platform, and is the canonical tool for building Haskell code. This section explains using Cabal, but where it lacks, you can get more info at: http://www.haskell.org/cabal/.

Getting Started with Cabal

A few helpful commands for getting started with Cabal:

  • cabal --help shows you all the Cabal commands. Highly recommended.
  • cabal update updates Cabal so that it has all of the latest package information.
  • cabal init runs you through a series of questions to start a new project.
  • cabal build builds your project locally (into the dist directory).
  • cabal test builds your project and then runs all of your tests.
  • cabal repl runs GHCI with your project already loaded.
  • cabal install installs a package.
    • Given zero arguments, it will install your package.
    • Given any number of library arguments (like cabal install github which was used above), it will download those libraries from hackage, build, and install them.
    • Given --only-dependencies, it will install all your package's dependencies. This is the recommended way to install new libraries to a project, as it will choose a version to install that is compatible with your other dependencies.

This project is a working Cabal project, and this document explains the Cabal configuration, which is in haskellstarter.cabal. Let's get started by taking a quick peek at it, and we'll create a Haskell library.

Cabal file header

name:                haskell-starter
version:             0.1.0.0
synopsis:            A demo for getting a project started in Haskell.
homepage:            https://github.com/joshcough/HaskellStarter
license:             MIT
license-file:        LICENSE
author:              Josh Cough
maintainer:          [email protected]
category:            Demo
build-type:          Simple
cabal-version:       >=1.8

source-repository head
  type: git
    location: [email protected]:joshcough/HaskellStarter.git

Most of these fields are self explanatory, and are mostly for documentation, and only a couple of them are required. More information on what each of these fields means and which ones are required can be found at http://www.haskell.org/cabal/users-guide/developing-packages.html.

Creating a Library

Modules

In order to have a library, we need some code.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap