okasaki

Okasaki's Purely Functional Data Structures
Log | Files | Refs | LICENSE

commit 3e3ee09745af8c15873103c399f2cc9a9c402763
parent 55af38a07988553ffc7709dafe75c3a852ed3523
Author: Jared Tobin <jared@jtobin.ca>
Date:   Wed, 19 Nov 2014 23:14:52 +1300

Misc.

Diffstat:
A.gitignore | 3+++
ALICENSE | 20++++++++++++++++++++
ASetup.hs | 2++
MStack.hs | 17+++++------------
Aokasaki.cabal | 18++++++++++++++++++
5 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,3 @@ +.cabal-sandbox +cabal.sandbox.config +*swp diff --git a/LICENSE b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014 Jared Tobin + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Setup.hs b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/Stack.hs b/Stack.hs @@ -6,10 +6,6 @@ import Prelude hiding (head, tail) data Stack a = Nil | Cons a (Stack a) deriving (Eq, Show) -instance Functor Stack where - fmap _ Nil = Nil - fmap f (Cons h t) = Cons (f h) (fmap f t) - isEmpty :: Stack a -> Bool isEmpty Nil = True isEmpty _ = False @@ -35,14 +31,11 @@ toList :: Stack a -> [a] toList Nil = [] toList (Cons h t) = h : toList t -append :: Stack a -> Maybe (Stack a) -> Maybe (Stack a) -append xs ys - | isEmpty xs = ys - | otherwise = do - h <- head xs - txs <- tail xs - t <- append txs ys - return (cons h t) +append :: Stack a -> Stack a -> Stack a +append Nil ys = ys +append (Cons h t) ys = + let txs = append t ys + in cons h txs update :: Stack a -> Int -> a -> Maybe (Stack a) update Nil _ _ = Nothing diff --git a/okasaki.cabal b/okasaki.cabal @@ -0,0 +1,18 @@ +name: okasaki +version: 0.1.0.0 +synopsis: Okasaki's Purely Functional Data Structures +homepage: http://github.com/jtobin/okasaki +license: MIT +license-file: LICENSE +author: Jared Tobin +maintainer: jared@jtobin.ca +build-type: Simple +cabal-version: >=1.10 + +library + exposed-modules: Stack, Tree + default-language: Haskell2010 + build-depends: + base >= 4.7 && < 4.8 + , QuickCheck >= 2.7.6 +