2010-12-25

Nested workspaces

For those who miss old nest_ws.lua the new API of Ion3 allows you to attach new tiling workspace to current WMPlex with:
_:attach_new({type="WGroupWS", switchto=true}):attach_new({type="WTiling", sizepolicy="full", bottom=true})
So your submenu, probably will look like:
defmenu("menuattach", {
    menuentry("Float WS", "_:attach_new({type=\"WGroupWS\", switchto=true})"),
    menuentry("Tiling WS", "_:attach_new({type=\"WGroupWS\", switchto=true}):attach_new({type=\"WTiling\", sizepolicy=\"full\", bottom=true})"),
})
As I understand there is no more pane workspace.
P.S. That's true for ion3-20090110

2010-12-11

Generics+specialization vs plain Interfaces.

For those who is interested in what comes out of generics and interfaces uses. Let's look at example:

2010-06-08

intset

There is std::vector specialization known as bit_vector. In the same way there may exist set of integers by using pages of bits accessed through std::map.

2010-04-25

Isn't that funny?...
class SuperType a b c | a b -> c
class Coerce a b where
    coerce :: a -> b

instance (Coerce a c, Coerce b d) => Coerce (a, b) (c, d) where
    coerce (a, b) = (coerce a, coerce b)

coerceSuper :: (SuperType a b c, Coerce a c, Coerce b c) => (a, b) -> (c, c)
coerceSuper = coerce

instance (Integral a, Integral b) => SuperType a b Integer
    -- I'm too lazy to enumerate supertype for all pairs

instance Integral a => Coerce a Integer where coerce = toInteger

-- ANum
class (Integral a, Num a) => NumCoerce a
instance (Integral a, Num a) => NumCoerce a

data ANum = forall a . NumCoerce a => ANum a

instance Show ANum where showsPrec n (ANum a) = showsPrec n a

instance Eq ANum where
    (ANum a) == (ANum b) = (uncurry (==) . coerceSuper) (a,b)

instance Num ANum where
    (ANum a) + (ANum b) = (ANum . uncurry (+) . coerceSuper) (a,b)
    (ANum a) * (ANum b) = (ANum . uncurry (*) . coerceSuper) (a,b)
    (ANum a) - (ANum b) = (ANum . uncurry (-) . coerceSuper) (a,b)
    negate (ANum a) = ANum (negate a)
    abs (ANum a) = ANum (abs a)
    signum (ANum a) = ANum (signum a)
    fromInteger = ANum
One thing I really miss is nice way to create type-sets like NumCoerce a

2010-01-21

By some reason Data.Decimal from Decimal-0.1.0 misses instance for Fractional instance Integral i => Fractional (DecimalRaw i) where (Decimal _ 0) / (Decimal _ ym) | ym /= 0 = Decimal 0 0 (Decimal p0 m0) / (Decimal 0 d) = divRem (Decimal p0 0) m0 where divRem z 0 = z -- out of decimalPlaces divRem (Decimal p m) r | p == maxBound = Decimal p (m + dm) where -- round for last digit dm | r'*2 >= d = dm0+1 | otherwise = dm0 (dm0, r') = r `divMod` d divRem (Decimal p m) r | r < d = divRem (Decimal (p+1) (m*10)) (r*10) divRem (Decimal p m) r = divRem (Decimal p (m+dm)) r' where (dm, r') = r `divMod` d -- divide decimalPlaces (Decimal xp xm) / (Decimal yp ym) | yp <= xp = Decimal (xp-yp) xm / Decimal 0 ym | otherwise = Decimal 0 (xm * (10^(yp-xp))) / Decimal 0 ym fromRational r = fromIntegral (numerator r) / fromIntegral (denominator r) class Scalable a where scale :: Integral b => Ratio b -> a -> a ratio :: Integral b => a -> a -> Ratio b instance Integral a => Scalable (DecimalRaw a) where r `scale` x = (x * n) / d where n = fromIntegral (numerator r) d = fromIntegral (denominator r) (Decimal xp xm) `ratio` (Decimal yp ym) = (fromIntegral xm * (10^yp)) % (fromIntegral ym * (10^xp))