Skip to content

Commit

Permalink
Moving from hg
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymorris committed Jun 30, 2011
0 parents commit d12d5a0
Show file tree
Hide file tree
Showing 26 changed files with 1,800 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .ghci
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:m + Test.QuickCheck
:l Course.hs
:m + Course
:set prompt ">> "
:set -Wall
:set -fno-warn-orphans
:set -fno-warn-type-defaults
:set -fno-warn-name-shadowing
:set -fno-warn-unused-do-bind

11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax: glob
*.swp
*.*~
*.o
*.orig
*.hi
*.lkshs
*/.idea/ant.xml
*/.idea/workspace.xml
dist
out
52 changes: 52 additions & 0 deletions Course.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Name: HaskellCourse
Version: 0.0.3
License: BSD3
License-File: LICENSE
Author: Tony Morris <[email protected]>
Maintainer: Tony Morris
Homepage: https://bitbucket.org/dibblego/haskell-course
Synopsis: Source code for a functional programming course
Category: Education
Description: Source code for a course in functional programming using Haskell
Cabal-version: >= 1.2
Build-Type: Simple

Flag small_base
Description: Choose the new, split-up base package.

Library
Build-Depends: base < 5 && >= 4,
split,
containers,
array,
directory,
filepath,
HUnit,
QuickCheck,
test-framework,
test-framework-hunit,
test-framework-quickcheck2

GHC-Options: -Wall
-fno-warn-orphans
-fno-warn-type-defaults
-fno-warn-name-shadowing
-fno-warn-unused-do-bind

Exposed-Modules: Answer.Replace
Course
L01.Optional
L01.Validation
L02.List
L03.Person
L03.Parser
L04.Fluffy
L04.Misty
L04.Tests
L05.Testing
L06.JsonValue
L06.MoreParser
L06.JsonParser
L07.Anagrams
L08.FastAnagrams
L09.EditDistance
38 changes: 38 additions & 0 deletions Course.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Course
(
module L01.Optional
, module L01.Validation
, module L02.List
, module L03.Person
, module L03.Parser
, module L04.Fluffy
, module L04.Misty
, module L04.Tests
, module L05.Testing
, module L06.JsonValue
, module L06.MoreParser
, module L06.JsonParser
, module L07.Anagrams
, module L08.FastAnagrams
, module L09.EditDistance
, module L09.MetricSpace
, module L09.BKTree
) where

import L01.Optional
import L01.Validation
import L02.List
import L03.Person
import L03.Parser hiding (tests)
import L04.Fluffy
import L04.Misty
import L04.Tests
import L05.Testing hiding (tests)
import L06.JsonValue
import L06.MoreParser
import L06.JsonParser
import L07.Anagrams
import L08.FastAnagrams
import L09.EditDistance
import L09.MetricSpace
import L09.BKTree
10 changes: 10 additions & 0 deletions Course.lkshw
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Version of workspace file format:
1
Time of storage:
"Tue Sep 7 14:29:28 EST 2010"
Name of the workspace:
"Course"
File paths of contained packages:
["Course.cabal"]
Maybe file path of an active package:
Just "Course.cabal"
24 changes: 24 additions & 0 deletions L01/Optional.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module L01.Optional where

-- class Optional<A> {
-- Optional(A a) {} // Full
-- Optional() {} // Empty
-- }
data Optional a = Full a | Empty deriving (Eq, Show)

mapOptional :: (a -> b) -> Optional a -> Optional b
mapOptional _ Empty = Empty
mapOptional f (Full a) = Full (f a)

bindOptional :: Optional a -> (a -> Optional b) -> Optional b
bindOptional Empty _ = Empty
bindOptional (Full a) f = f a

(??) :: Optional a -> a -> a
Empty ?? d = d
Full a ?? _ = a

(<+>) :: Optional a -> Optional a -> Optional a
Empty <+> o = o
k <+> _ = k

37 changes: 37 additions & 0 deletions L01/Validation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module L01.Validation where

type Err = String

-- class Validation<A> {
-- Validation(String error) {} // Error
-- Validation(A value) {} // Value
-- }
data Validation a = Error Err | Value a
deriving (Eq, Show)

isError :: Validation a -> Bool
isError (Error _) = True
isError (Value _) = False

isValue :: Validation a -> Bool
isValue = not . isError

mapValidation :: (a -> b) -> Validation a -> Validation b
mapValidation _ (Error s) = Error s
mapValidation f (Value a) = Value (f a)

bindValidation :: Validation a -> (a -> Validation b) -> Validation b
bindValidation (Error s) _ = Error s
bindValidation (Value a) f = f a

valueOr :: Validation a -> a -> a
valueOr (Error _) a = a
valueOr (Value a) _ = a

errorOr :: Validation a -> Err -> Err
errorOr (Error e) _ = e
errorOr (Value _) a = a

valueValidation :: a -> Validation a
valueValidation = Value

Loading

0 comments on commit d12d5a0

Please sign in to comment.