Skip to content

Loading…

<$> From Haskell #1

Merged
merged 3 commits into from

2 participants

@jasonjckn

I see you have >>==, but I've never seen this in haskell.

In haskell there's <$> and liftM, my diff adds <$>

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Applicative.html#v:<$>

@jasonjckn

btw, this is the best parsing library for clojure I've seen.

@jasonjckn jasonjckn closed this
@jasonjckn jasonjckn reopened this
@devn devn merged commit c67bc7f into devn:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 2, 2011
  1. added haskell applicative style programming <$> function

    Jason Jackson committed
  2. fixed param ordering on <$>

    Jason Jackson committed
  3. fixed bug where calling many with a recursive parser would cause stac…

    Jason Jackson committed
    …koverflow.
Showing with 8 additions and 6 deletions.
  1. +3 −4 project.clj
  2. +5 −2 src/eu/dnetlib/clojure/clarsec.clj
View
7 project.clj
@@ -1,6 +1,5 @@
(defproject clarsec "0.0.1-SNAPSHOT"
:description "Parsec ported to clojure"
- :dependencies [[org.clojure/clojure "1.1.0"]
- [org.clojure/clojure-contrib "1.0-SNAPSHOT"]]
- :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]]
- :main eu.dnetlib.dlms.parser)
+ :dependencies [[org.clojure/clojure "1.2.1"]
+ [org.clojure/clojure-contrib "1.2.0"]]
+ :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]])
View
7 src/eu/dnetlib/clojure/clarsec.clj
@@ -59,6 +59,9 @@
;; Bind with a non monadic function
(defn >>== [p f]
(bind p #(result (f %))))
+(defn <$> [f p]
+ (bind p #(result (f %))))
+
(def any-token
(make-monad 'Parser
@@ -101,7 +104,7 @@
(def many1)
(defn many [parser]
- (>>== (optional (many1 parser))
+ (>>== (optional (delay (many1 parser)))
#(if (nil? %) () %)))
(defn many1 [parser]
@@ -195,4 +198,4 @@
((monad (force parser)) input))
;;(defn -main []
-;; (println (parse (>> (delay letter) (delay letter)) "ca.")))
+;; (println (parse (>> (delay letter) (delay letter)) "ca.")))
Something went wrong with that request. Please try again.