]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge commit '53059ca'
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 3 Nov 2016 20:33:39 +0000 (22:33 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 3 Nov 2016 20:33:39 +0000 (22:33 +0200)
Conflicts:
bundles/org.simantics.scl.runtime/scl/Prelude.scl

refs #6726
refs #6788
refs #6791

1  2 
bundles/org.simantics.scl.runtime/scl/Prelude.scl

index 6966b4489d0652c61b8cde57fc7d185b75a2dd08,0dcd1b7507d6ee99ee2866c174f5b987ee1e77e0..21658862db66f34262c1852603872ff5f25291ef
@@@ -558,43 -558,6 +558,43 @@@ importJava "java.lang.Math" wher
  
  /// Integer ///
  
 +@private
 +importJava "java.lang.Byte" where
 +    @JavaName toString
 +    showByte :: Byte -> String
 +    
 +    @JavaName parseByte
 +    readByte :: String -> Byte
 +
 +instance Eq Byte where
 +    (==) = Java.bcmpeq
 +    (!=) = Java.bcmpne
 +
 +instance Ord Byte where
 +    (<) = Java.bcmplt
 +    (<=) = Java.bcmple
 +    (>) = Java.bcmpgt
 +    (>=) = Java.bcmpge
 +    
 +instance Additive Byte where
 +    zero = Java.i2b Java.iconst_0
 +    (+) = Java.badd
 +    
 +instance Ring Byte where
 +    neg = Java.bneg
 +    (-) = Java.bsub
 +    one = Java.i2b Java.iconst_1
 +    (*) = Java.bmul
 +    fromInteger = Java.i2b
 +
 +instance Show Byte where
 +    show = showByte
 +    precedence v = if v >= 0 then 0 else 100
 +
 +instance Read Byte where
 +    read = readByte
 +
 +
  @private
  importJava "java.lang.Short" where
      @JavaName toString
@@@ -1303,7 -1266,7 +1303,7 @@@ instance MonadZero Maybe wher
      mzero = Nothing
  
  instance MonadOr Maybe where
 -    morelse (Just a) _ = Just a
 +    morelse a@(Just _) _ = a
      morelse _ b = b
  
  "`execJust v f` executes the function `f` with parameter value `x`, if `v=Just x`. If `v=Nothing`, the function does nothing."
@@@ -1879,6 -1842,17 +1879,17 @@@ maybeToList :: Maybe a -> [a
  maybeToList (Just a) = [a]
  maybeToList _ = [] 
  
+ """
+ `takeWhile p l`, returns the longest prefix (possibly empty) of list `l` of elements that satisfy `p`
+ """
+ takeWhile :: (a -> <e> Boolean) -> [a] -> <e> [a]
+ takeWhile f l = loop 0 
+   where
+     len = length l
+     loop i | i == len  = l
+            | f (l!i)   = loop (i+1)
+            | otherwise = take i l
  partition :: (a -> <e> Boolean) -> [a] -> <e> ([a], [a])
  partition p l = runProc do
      res1 = newArrayList
@@@ -2266,7 -2240,45 +2277,7 @@@ instance Show TypeRep wher
          isSpecialType (TCon "Builtin" "(,,,)") = True
          isSpecialType (TApply a _) = isSpecialType a
  */
 -// Serializable
 -
 -importJava "org.simantics.databoard.serialization.Serializer" where
 -    data Serializer a
 -
 -    @private
 -    @JavaName "serialize"    
 -    serialize_ :: Serializer a -> a -> ByteArray
 -    
 -    @private
 -    @JavaName "deserialize"
 -    deserialize_ :: Serializer a -> ByteArray -> a
 -
 -importJava "org.simantics.databoard.Bindings" where
 -    @private
 -    @JavaName "getSerializer"
 -    serializerOf :: Binding a -> Serializer a
 -    
 -    @private
 -    @JavaName toString
 -    bindingToString :: Binding a -> String
 -    
 -    @JavaName adapt
 -    adapt_ :: a -> Binding a -> Binding b -> b
 -    
 -adapt :: Serializable a => Serializable b => a -> b
 -adapt x = adapt_ x binding binding
 -    
 -instance Show (Binding a) where
 -    show = bindingToString
  
 -"Serializes a value to a byte array."
 -serialize :: Serializable a => a -> ByteArray
 -serialize v = serialize_ (serializerOf binding) v
 -
 -"Deserializes a value from a byte array."
 -deserialize :: Serializable a => ByteArray -> a
 -deserialize ba = deserialize_ (serializerOf binding) ba
 -    
  // ByteArray
  
  importJava "java.util.Arrays" where
  instance Show ByteArray where
      show = byteArrayToString
  
 -importJava "org.simantics.databoard.binding.mutable.Variant" where
 -    // data Variant (in Builtins)
 -    @JavaName getValue
 -    rawVariantValue :: Variant -> a
 -    @JavaName ofInstance
 -    variantOf :: a -> Variant
 -    @JavaName "<init>"
 -    variantOfWithBinding :: Binding a -> a -> Variant
 -    @JavaName getValue
 -    variantValue_ :: Variant -> Binding a -> a
 -    @JavaName toString
 -    showVariant :: Variant -> String
 -    
 -    @JavaName getComponent
 -    variantComponent :: Variant -> ChildReference -> Variant
 -
 -variantValue :: Serializable a => Variant -> a
 -variantValue v = variantValue_ v binding
 -
 -instance Show Variant where
 -    show = showVariant
 -
 -variantElement :: Serializable a => Variant -> Integer -> a
 -variantElement v i = variantValue (variantComponent v (indexReference i))
 -
 -importJava "org.simantics.databoard.accessor.reference.ChildReference" where
 -    data ChildReference
 -
 -    @JavaName compile    
 -    compileReference :: [ChildReference] -> ChildReference
 -
 -importJava "org.simantics.databoard.accessor.reference.IndexReference" where
 -    @JavaName "<init>"
 -    indexReference :: Integer -> ChildReference
 -
 -importJava "org.simantics.databoard.accessor.reference.KeyReference" where
 -    @JavaName "<init>"
 -    keyReference :: Variant -> ChildReference
 -
 -importJava "org.simantics.databoard.accessor.reference.NameReference" where
 -    @JavaName "<init>"
 -    nameReference :: String -> ChildReference
 -    
 -importJava "org.simantics.databoard.accessor.reference.LabelReference" where
 -    @JavaName "<init>"
 -    labelReference :: String -> ChildReference
 -    
  // Type
  
  @private