CSS. Cascading Style Sheets. What are they?
Wikipedia says:
Cascading Style Sheets (CSS) is a style sheet language used for describing...
And one important observation: there are no abstraction mechanism in CSS. CSS expression evaluates to itself. Thus CSS is not very fascinating as a programming language.
There are sass, lesscss and others. They add some abbstractions mechanisms, notably variables and mixins (which are kind-of-functions). Yet I don't like them as languages, they are barely macro systems.
It would be nice to have pure (do you really need side-effects while generating CSS?) typed, well-designed CSS abstraction language.
Below is something I have in mind:
If you look at SASS' Variable Scope and Content Blocks -example:
$color: white;
@mixin colors($color: blue) {
background-color: $color;
@content;
border-color: $color;
}
.colors {
@include colors { color: $color; }
}
It could be:
color : Color
color = white
colors : Color -> Content -> Block
colors (color = blue) content = {
background-color: color;
content; -- slicing in, obvious by type. Or is type obvious by slicing?
border-color: color;
}
.colors {
colors _ { color: color; }; -- again sliced in, as result is Block
-- And first argument value is inferred (as there is a default value)
}
@each $animal in puma, sea-slug, egret, salamander {
.#{$animal}-icon {
background-image: url('/images/#{$animal}.png');
}
}
animals : [String]
animals = ["puma", "sea-slug", "egret", "salamander"]
-- all top level expressions, which aren't binding forms, are printed
for animals λ animal -> selector ("." ++ animal ++ "-icon") {
background-image: url("/images/" ++ animal ++ ".png");
}
-- for : ∀ a b, [a] -> (a -> b) -> [b]
-- for = flip map
*So the question I try to ask is probably: *Is it possible to define language, which is syntactically superset of CSS, such that
- it is typed
- it is closer to Haskell than to BASIC
And if answer is yes, can someone implement one?