[Fencommits] fenfire-hs: refactor more
Benja Fallenstein
benja.fallenstein at gmail.com
Wed Feb 28 18:50:44 EET 2007
Wed Feb 28 18:50:29 EET 2007 Benja Fallenstein <benja.fallenstein at gmail.com>
* refactor more
diff -rN -u old-fenfire-hs/Fenfire.fhs new-fenfire-hs/Fenfire.fhs
--- old-fenfire-hs/Fenfire.fhs 2007-02-28 18:50:44.000000000 +0200
+++ new-fenfire-hs/Fenfire.fhs 2007-02-28 18:50:44.000000000 +0200
@@ -24,13 +24,13 @@
import Vobs
import Utils
import qualified Raptor
+import URN5
import RDF
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.List as List
import Data.Set (Set)
-import Data.IORef
import Data.Maybe (fromMaybe, fromJust, isJust, isNothing, catMaybes)
import Data.Monoid(Monoid(mempty, mconcat))
@@ -40,7 +40,6 @@
import qualified Network.URI
import System.Mem.StableName
-import System.Random (randomRIO)
data ViewSettings = ViewSettings { hiddenProps :: [Node], maxCenter :: Int }
data FenState = FenState {
@@ -151,24 +150,11 @@
state { fsGraph=graph', fsPath=path', fsGraphModified=True,
fsUndo=(fsGraph state, fsPath state):fsUndo state, fsRedo=[]}
-type URIMaker = (String, IORef Integer)
-
-newURIMaker :: IO URIMaker
-newURIMaker = do rand <- sequence [randomRIO (0,63) | _ <- [1..27::Int]]
- let chars = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "+-"
- ref <- newIORef 1
- return ("urn:urn-5:" ++ map (chars !!) rand, ref)
-
-newURI :: (?uriMaker :: URIMaker) => IO Node
-newURI = do let (base, ref) = ?uriMaker
- i <- readIORef ref; writeIORef ref (i+1)
- return $ URI (base ++ ":_" ++ show i)
-
newNode :: (?vs :: ViewSettings, ?uriMaker :: URIMaker) =>
Dir -> EndoM IO FenState
newNode dir state@(FenState { fsGraph = graph, fsProperty = prop,
fsPath = Path node _ }) = do
- node' <- newURI
+ node' <- liftM URI newURI
let graph' = insert (triple dir (node, prop, node'))
$ insert (node', rdfs_label, PlainLiteral "") graph
in return $ modifyGraph graph' (Path node' [Conn prop (rev dir) node]) state
@@ -203,7 +189,7 @@
newGraph :: (?uriMaker :: URIMaker) => IO (Graph, Path)
newGraph = do
- home <- newURI
+ home <- liftM URI newURI
let graph = listToGraph [(home, rdfs_label, PlainLiteral "")]
return (graph, Path home [])
diff -rN -u old-fenfire-hs/Main.hs new-fenfire-hs/Main.hs
--- old-fenfire-hs/Main.hs 2007-02-28 18:50:44.000000000 +0200
+++ new-fenfire-hs/Main.hs 2007-02-28 18:50:44.000000000 +0200
@@ -22,6 +22,7 @@
import Cairo hiding (Path, rotate)
import Vobs
import qualified Raptor
+import URN5
import RDF
import VanishingView
import Fenfire
diff -rN -u old-fenfire-hs/URN5.hs new-fenfire-hs/URN5.hs
--- old-fenfire-hs/URN5.hs 1970-01-01 02:00:00.000000000 +0200
+++ new-fenfire-hs/URN5.hs 2007-02-28 18:50:44.000000000 +0200
@@ -0,0 +1,36 @@
+module URN5 where
+
+-- Copyright (c) 2006-2007, Benja Fallenstein, Tuukka Hastrup
+-- This file is part of Fenfire.
+--
+-- Fenfire is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- Fenfire is distributed in the hope that it will be useful, but WITHOUT
+-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+-- Public License for more details.
+--
+-- You should have received a copy of the GNU General
+-- Public License along with Fenfire; if not, write to the Free
+-- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+-- MA 02111-1307 USA
+
+import Data.IORef
+import System.Random (randomRIO)
+
+type URIMaker = (String, IORef Integer)
+
+newURIMaker :: IO URIMaker
+newURIMaker = do rand <- sequence [randomRIO (0,63) | _ <- [1..27::Int]]
+ let chars = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "+-"
+ ref <- newIORef 1
+ return ("urn:urn-5:" ++ map (chars !!) rand, ref)
+
+newURI :: (?uriMaker :: URIMaker) => IO String
+newURI = do let (base, ref) = ?uriMaker
+ i <- readIORef ref; writeIORef ref (i+1)
+ return (base ++ ":_" ++ show i)
+
More information about the Fencommits
mailing list