]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/LP.scl
Fixed all line endings of the repository
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / LP.scl
index 0c3ddc1217a2a5313b1c37a7384e9844990bb550..98b8fa48446e3dca80340c0808b5e363ffbcdaad 100644 (file)
@@ -1,86 +1,86 @@
-import "Prelude"\r
-\r
-importJava "gnu.trove.map.hash.TIntFloatHashMap" where\r
-    data LMap\r
-    \r
-    @JavaName adjustOrPutValue\r
-    adjustLMap_ :: LMap -> Integer -> Float -> Float -> <Proc> ()\r
-    \r
-@inline\r
-adjustLMap :: LMap -> Integer -> Float -> <Proc> ()\r
-adjustLMap m k v = adjustLMap_ m k v v\r
-\r
-data LPTerm = LPTerm (LMap -> Float -> <Proc> ())\r
-\r
-instance Additive LPTerm where\r
-    @inline\r
-    zero = LPTerm (\_ _ -> ())\r
-    @inline\r
-    LPTerm a + LPTerm b = LPTerm (\m s -> do a m s ; b m s)\r
-    sum ts = LPTerm (\m s -> for ts (\(LPTerm t) -> t m s))\r
-\r
-instance Ring LPTerm where\r
-    @inline\r
-    neg (LPTerm a) = LPTerm (\m s -> a m (-s))\r
-    @inline\r
-    LPTerm a - LPTerm b = LPTerm (\m s -> do a m s ; b m (-s))\r
-    @inline\r
-    fromInteger c = LPTerm (\m s -> adjustLMap m (-1) (fromInteger c*s))\r
-    @inline\r
-    one = LPTerm (\m s -> adjustLMap m (-1) s)\r
-    _ * _ = fail "Multiplication is not supported."\r
-\r
-data LPProblem = LPProblem (Ref Integer)\r
-\r
-newProblem :: () -> <Proc> LPProblem\r
-newProblem _ = LPProblem (ref 0)\r
-\r
-newVar :: LPProblem -> <Proc> LPTerm\r
-newVar (LPProblem varCounter) = do\r
-    curId = getRef varCounter\r
-    varCounter := curId + 1\r
-    LPTerm (\m s -> adjustLMap m curId s)\r
-\r
-infixl 7 (**)\r
-\r
-@inline\r
-(**) :: Float -> LPTerm -> LPTerm\r
-s0 ** LPTerm t = LPTerm (\m s -> t m (s0*s))\r
-\r
-/*\r
-data LPTerm = LPTerm Double (Map.T String Double)\r
-\r
-instance Additive LPTerm where\r
-    zero = LPTerm 0 Map.empty\r
-    LPTerm c1 m1 + LPTerm c2 m2 = LPTerm (c1+c2) (Map.merge (+) m1 m2)\r
-\r
-instance Ring LPTerm where\r
-    one = LPTerm 1 Map.empty\r
-    neg (LPTerm c m) = LPTerm (-c) (map neg m)\r
-    LPTerm c1 m1 - LPTerm c2 m2 = LPTerm (c1-c2) (Map.merge (-) m1 m2)\r
-    \r
-    LPTerm c1 [] * LPTerm c2 m2 = LPTerm (c1*c2) (Map.merge (\x -> c1*x) m2)\r
-    LPTerm c1 m1 * LPTerm c2 [] = LPTerm (c1*c2) (Map.merge (\x -> c2*x) m1)\r
-    _ * _ = fail "Invalid expression: not linear."\r
-    \r
-    fromInteger i = LPTerm (fromInteger i) Map.empty\r
-\r
-data LPConstraint = LPConstraint String LPTerm\r
-\r
-(>==) :: LPTerm -> LPTerm -> String -> [LPConstraint]\r
-(a >== b) name = [LPConstraint name (a-b)] \r
-\r
-(<==) :: LPTerm -> LPTerm -> String -> [LPConstraint]\r
-(a <== b) name = [LPConstraint name (b-a)]\r
-\r
-*/\r
-\r
-testi () = do\r
-    problem = newProblem ()\r
-    a = newVar problem\r
-    b = newVar problem\r
-    3 ** a + 4 ** b + 15\r
-\r
-main = "OK"\r
---\r
+import "Prelude"
+
+importJava "gnu.trove.map.hash.TIntFloatHashMap" where
+    data LMap
+    
+    @JavaName adjustOrPutValue
+    adjustLMap_ :: LMap -> Integer -> Float -> Float -> <Proc> ()
+    
+@inline
+adjustLMap :: LMap -> Integer -> Float -> <Proc> ()
+adjustLMap m k v = adjustLMap_ m k v v
+
+data LPTerm = LPTerm (LMap -> Float -> <Proc> ())
+
+instance Additive LPTerm where
+    @inline
+    zero = LPTerm (\_ _ -> ())
+    @inline
+    LPTerm a + LPTerm b = LPTerm (\m s -> do a m s ; b m s)
+    sum ts = LPTerm (\m s -> for ts (\(LPTerm t) -> t m s))
+
+instance Ring LPTerm where
+    @inline
+    neg (LPTerm a) = LPTerm (\m s -> a m (-s))
+    @inline
+    LPTerm a - LPTerm b = LPTerm (\m s -> do a m s ; b m (-s))
+    @inline
+    fromInteger c = LPTerm (\m s -> adjustLMap m (-1) (fromInteger c*s))
+    @inline
+    one = LPTerm (\m s -> adjustLMap m (-1) s)
+    _ * _ = fail "Multiplication is not supported."
+
+data LPProblem = LPProblem (Ref Integer)
+
+newProblem :: () -> <Proc> LPProblem
+newProblem _ = LPProblem (ref 0)
+
+newVar :: LPProblem -> <Proc> LPTerm
+newVar (LPProblem varCounter) = do
+    curId = getRef varCounter
+    varCounter := curId + 1
+    LPTerm (\m s -> adjustLMap m curId s)
+
+infixl 7 (**)
+
+@inline
+(**) :: Float -> LPTerm -> LPTerm
+s0 ** LPTerm t = LPTerm (\m s -> t m (s0*s))
+
+/*
+data LPTerm = LPTerm Double (Map.T String Double)
+
+instance Additive LPTerm where
+    zero = LPTerm 0 Map.empty
+    LPTerm c1 m1 + LPTerm c2 m2 = LPTerm (c1+c2) (Map.merge (+) m1 m2)
+
+instance Ring LPTerm where
+    one = LPTerm 1 Map.empty
+    neg (LPTerm c m) = LPTerm (-c) (map neg m)
+    LPTerm c1 m1 - LPTerm c2 m2 = LPTerm (c1-c2) (Map.merge (-) m1 m2)
+    
+    LPTerm c1 [] * LPTerm c2 m2 = LPTerm (c1*c2) (Map.merge (\x -> c1*x) m2)
+    LPTerm c1 m1 * LPTerm c2 [] = LPTerm (c1*c2) (Map.merge (\x -> c2*x) m1)
+    _ * _ = fail "Invalid expression: not linear."
+    
+    fromInteger i = LPTerm (fromInteger i) Map.empty
+
+data LPConstraint = LPConstraint String LPTerm
+
+(>==) :: LPTerm -> LPTerm -> String -> [LPConstraint]
+(a >== b) name = [LPConstraint name (a-b)] 
+
+(<==) :: LPTerm -> LPTerm -> String -> [LPConstraint]
+(a <== b) name = [LPConstraint name (b-a)]
+
+*/
+
+testi () = do
+    problem = newProblem ()
+    a = newVar problem
+    b = newVar problem
+    3 ** a + 4 ** b + 15
+
+main = "OK"
+--
 OK
\ No newline at end of file