-
Notifications
You must be signed in to change notification settings - Fork 11
Week11 #153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cht8687
wants to merge
41
commits into
fp-works:master
Choose a base branch
from
cht8687:week11
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Week11 #153
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
1340085
[Homework01-Task4]:validate
cht8687 46b7705
merge
cht8687 683385a
Week2-Task1
cht8687 1663cb8
update
cht8687 2b4e59b
ViewPattern
cht8687 64eca0f
Merge remote-tracking branch 'upstream/master'
cht8687 38160c5
update readme
cht8687 1bd8a29
merge
cht8687 53720c1
task 1
cht8687 82f8c7a
Merge remote-tracking branch 'upstream/master'
cht8687 5a964e2
Task2
cht8687 d272163
merge
cht8687 2c5b76f
change names
cht8687 272c2f1
Merge remote-tracking branch 'upstream/master'
cht8687 b5c8116
[Week4]:Task1]
cht8687 a4b4b99
Task1-2nd solution
cht8687 ecb3165
update
cht8687 e6d24c3
[week4]Task3-1
cht8687 850701e
Merge remote-tracking branch 'upstream/master'
cht8687 696a0f8
Merge remote-tracking branch 'upstream/master'
cht8687 425a656
[Week5]T1,T2,T3,T4
cht8687 1181229
Merge remote-tracking branch 'upstream/master'
cht8687 e29d702
Week6-1,2,3,4
cht8687 26e6843
week6:task5
cht8687 08428e0
merge
cht8687 c681281
(week7):Task[1..2]
cht8687 ecbb6b4
Merge remote-tracking branch 'upstream/master'
cht8687 343c8fb
[week7]:Task2.2
cht8687 f47ed90
merge upstream
cht8687 0f0badb
(week7): Task2-3
cht8687 b16680d
merge
cht8687 0677ec9
refactored to shorter
cht8687 93d8835
WIP
cht8687 795bfe9
merge
cht8687 5ee541d
[Week10]: Task 1 -> Functor
cht8687 6628f9d
(week7)-task3
cht8687 7db4986
[week10]:Task2
cht8687 f2da9ba
remove duplicates
cht8687 09bfd21
Merge remote-tracking branch 'upstream/master'
cht8687 18ca0d4
Merge remote-tracking branch 'upstream/master'
cht8687 ae65580
(week11): 1-3
cht8687 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .stack-work/ | ||
| haotian.cabal | ||
| *~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Changelog for haotian | ||
|
|
||
| ## Unreleased changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # haotian |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import Distribution.Simple | ||
| main = defaultMain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Main where | ||
|
|
||
| import Lib | ||
|
|
||
| main :: IO () | ||
| main = someFunc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Lib | ||
| ( someFunc | ||
| ) where | ||
|
|
||
| someFunc :: IO () | ||
| someFunc = putStrLn "someFunc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "" | ||
|
|
||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| main :: IO () | ||
| main = putStrLn "Test suite not yet implemented" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.