Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1340085
[Homework01-Task4]:validate
cht8687 Aug 9, 2019
46b7705
merge
cht8687 Aug 14, 2019
683385a
Week2-Task1
cht8687 Aug 14, 2019
1663cb8
update
cht8687 Aug 15, 2019
2b4e59b
ViewPattern
cht8687 Aug 15, 2019
64eca0f
Merge remote-tracking branch 'upstream/master'
cht8687 Aug 16, 2019
38160c5
update readme
cht8687 Aug 17, 2019
1bd8a29
merge
cht8687 Aug 24, 2019
53720c1
task 1
cht8687 Aug 26, 2019
82f8c7a
Merge remote-tracking branch 'upstream/master'
cht8687 Aug 26, 2019
5a964e2
Task2
cht8687 Aug 28, 2019
d272163
merge
cht8687 Aug 28, 2019
2c5b76f
change names
cht8687 Aug 28, 2019
272c2f1
Merge remote-tracking branch 'upstream/master'
cht8687 Aug 31, 2019
b5c8116
[Week4]:Task1]
cht8687 Aug 31, 2019
a4b4b99
Task1-2nd solution
cht8687 Aug 31, 2019
ecb3165
update
cht8687 Aug 31, 2019
e6d24c3
[week4]Task3-1
cht8687 Sep 1, 2019
850701e
Merge remote-tracking branch 'upstream/master'
cht8687 Sep 8, 2019
696a0f8
Merge remote-tracking branch 'upstream/master'
cht8687 Sep 9, 2019
425a656
[Week5]T1,T2,T3,T4
cht8687 Sep 9, 2019
1181229
Merge remote-tracking branch 'upstream/master'
cht8687 Sep 16, 2019
e29d702
Week6-1,2,3,4
cht8687 Sep 22, 2019
26e6843
week6:task5
cht8687 Sep 25, 2019
08428e0
merge
cht8687 Sep 25, 2019
c681281
(week7):Task[1..2]
cht8687 Sep 29, 2019
ecbb6b4
Merge remote-tracking branch 'upstream/master'
cht8687 Sep 29, 2019
343c8fb
[week7]:Task2.2
cht8687 Oct 2, 2019
f47ed90
merge upstream
cht8687 Oct 2, 2019
0f0badb
(week7): Task2-3
cht8687 Oct 2, 2019
b16680d
merge
cht8687 Oct 2, 2019
0677ec9
refactored to shorter
cht8687 Oct 3, 2019
93d8835
WIP
cht8687 Oct 6, 2019
795bfe9
merge
cht8687 Oct 12, 2019
5ee541d
[Week10]: Task 1 -> Functor
cht8687 Oct 13, 2019
6628f9d
(week7)-task3
cht8687 Oct 13, 2019
7db4986
[week10]:Task2
cht8687 Oct 13, 2019
f2da9ba
remove duplicates
cht8687 Oct 14, 2019
09bfd21
Merge remote-tracking branch 'upstream/master'
cht8687 Oct 15, 2019
18ca0d4
Merge remote-tracking branch 'upstream/master'
cht8687 Oct 27, 2019
ae65580
(week11): 1-3
cht8687 Oct 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cis194/week11/haotian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.stack-work/
haotian.cabal
*~
3 changes: 3 additions & 0 deletions cis194/week11/haotian/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog for haotian

## Unreleased changes
30 changes: 30 additions & 0 deletions cis194/week11/haotian/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2019

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions cis194/week11/haotian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# haotian
2 changes: 2 additions & 0 deletions cis194/week11/haotian/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions cis194/week11/haotian/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = someFunc
48 changes: 48 additions & 0 deletions cis194/week11/haotian/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: haotian
version: 0.1.0.0
github: "githubuser/haotian"
license: BSD3
author: "Author name here"
maintainer: "[email protected]"
copyright: "2019 Author name here"

extra-source-files:
- README.md
- ChangeLog.md

# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web

# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/haotian#readme>

dependencies:
- base >= 4.7 && < 5

library:
source-dirs: src

executables:
haotian-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- haotian

tests:
haotian-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- haotian
44 changes: 44 additions & 0 deletions cis194/week11/haotian/src/AParser.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module AParser (Parser, runParser, satisfy, char, posInt) where

import Control.Applicative
import Data.Char

newtype Parser a = Parser { runParser :: String -> Maybe (a, String) }

satisfy :: (Char -> Bool) -> Parser Char
satisfy p = Parser f
where
f [] = Nothing
f (x:xs)
| p x = Just (x, xs)
| otherwise = Nothing

char :: Char -> Parser Char
char c = satisfy (== c)

posInt :: Parser Integer
posInt = Parser f
where
f xs
| null ns = Nothing
| otherwise = Just (read ns, rest)
where (ns, rest) = span isDigit xs

inParser f = Parser . f . runParser

first :: (a -> b) -> (a,c) -> (b,c)
first f (x,y) = (f x, y)

instance Functor Parser where
fmap = inParser . fmap . fmap . first

instance Applicative Parser where
pure a = Parser (\s -> Just (a, s))
(Parser fp) <*> xp = Parser $ \s ->
case fp s of
Nothing -> Nothing
Just (f,s') -> runParser (f <$> xp) s'

instance Alternative Parser where
empty = Parser (const Nothing)
Parser p1 <|> Parser p2 = Parser $ liftA2 (<|>) p1 p2
6 changes: 6 additions & 0 deletions cis194/week11/haotian/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"
60 changes: 60 additions & 0 deletions cis194/week11/haotian/src/SExpr.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{- CIS 194 HW 11
due Monday, 8 April
-}

module SExpr where

import AParser
import Control.Applicative
import Data.Char

------------------------------------------------------------
-- 1. Parsing repetitions
------------------------------------------------------------

zeroOrMore :: Parser a -> Parser [a]
zeroOrMore p = oneOrMore p <|> pure []

oneOrMore :: Parser a -> Parser [a]
oneOrMore p = (:) <$> p <*> zeroOrMore p

------------------------------------------------------------
-- 2. Utilities
------------------------------------------------------------

spaces :: Parser String
spaces = (:) <$> satisfy isSpace <*> spaces <|> pure ""
Copy link
Contributor

@tienwei tienwei Oct 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could also take advantage of zeroOrMore.


ident :: Parser String
ident = (:) <$> satisfy isAlpha <*> zeroOrMore (satisfy isAlphaNum)

------------------------------------------------------------
-- 3. Parsing S-expressions
------------------------------------------------------------

-- An "identifier" is represented as just a String; however, only
-- those Strings consisting of a letter followed by any number of
-- letters and digits are valid identifiers.
type Ident = String

-- An "atom" is either an integer value or an identifier.
data Atom = N Integer | I Ident
deriving Show

-- An S-expression is either an atom, or a list of S-expressions.
data SExpr = A Atom
| Comb [SExpr]
deriving Show

parseAtom :: Parser Atom
parseAtom = (I <$> ident) <|> (N <$> posInt)

withSpaces :: Parser a -> Parser a
withSpaces p = spaces *> p <* spaces

withParens :: Parser a -> Parser a
withParens p = char '(' *> p <* char ')'

parseSExpr :: Parser SExpr
parseSExpr = withSpaces $
(A <$> parseAtom) <|> withParens (Comb <$> oneOrMore parseSExpr)
66 changes: 66 additions & 0 deletions cis194/week11/haotian/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# https://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
#
# The location of a snapshot can be provided as a file or url. Stack assumes
# a snapshot provided as a file might change, whereas a url resource does not.
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-14.11

# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# subdirs:
# - auto-update
# - wai
packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.1"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
12 changes: 12 additions & 0 deletions cis194/week11/haotian/stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages: []
snapshots:
- completed:
size: 524786
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/14/11.yaml
sha256: 088bb91b545839510a41ae92fa5feb36779ef3529571a42bd12b9f51eb89ded3
original: lts-14.11
2 changes: 2 additions & 0 deletions cis194/week11/haotian/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"