I hereby claim:
- I am phaazon on github.
- I am phaazon (https://keybase.io/phaazon) on keybase.
- I have a public key whose fingerprint is 3943 DF2A 2E41 24B4 5702 E6BC 4F28 29BB 996A 2EED
To claim this, I am signing this object:
data Foo :: * -> * where -- the * -> * means that Foo expects a type to be concrete, so like Foo Int, Foo Bool, etc. | |
FooInt :: Int -> Foo Int | |
FooBool :: Bool -> Foo Bool | |
-- so the compiler can enforce that there is no way to build a Foo t where t is not either Int or Bool. | |
-- then, matching on Foo Int is exhaustive here: | |
matchIntOnly :: Foo Int -> Int | |
matchIntOnly (FooInt x) = x |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE Rank2Types #-} | |
import Data.Kind (Constraint) | |
-- This implementation is based on existentials; i.e. the type information is | |
-- lost when the type 'a' is wrapped in 'Impl c' (no 'a' anymore). | |
data Impl :: (* -> Constraint) -> * where |
pub fn from_hex(hex: impl AsRef<str>) -> Option<Color> { | |
let hex = hex.as_ref(); | |
let bytes = hex.as_bytes(); | |
let (mut r, mut g, mut b); | |
if hex.len() == 4 && bytes[0] == b'#' { | |
// triplet form (#rgb) | |
let mut h = u16::from_str_radix(&hex[1..], 16).ok()?; | |
b = (h & 0xf) as _; |
toBin8 :: Int8 -> Integer | |
toBin8 x = | |
y .&. 1 | |
+ (y `shiftR` 1 .&. 1) * 10 | |
+ (y `shiftR` 2 .&. 1) * 100 | |
+ (y `shiftR` 3 .&. 1) * 1000 | |
+ (y `shiftR` 4 .&. 1) * 10000 | |
+ (y `shiftR` 5 .&. 1) * 100000 | |
+ (y `shiftR` 6 .&. 1) * 1000000 | |
+ (y `shiftR` 7 .&. 1) * 10000000 |
// A depends on B-0.1 and C-0.1 | |
// B depends on C-0.1 | |
// in C | |
struct Foo; | |
struct Bar; | |
// in A | |
fn foo(_: Foo, _: Bar); |
-- Why not this implementation? | |
selectM :: (Monad f) => f (Either a b) -> f (a -> b) -> f b | |
selectM x y = do | |
e <- x | |
case e of | |
Left a -> fmap ($a) y | |
Right b -> b <$ y |
-- Why not this implementation? | |
selectM :: (Monad f) => f (Either a b) -> f (a -> b) -> f b | |
selectM x y = do | |
e <- x | |
case e of | |
Left a -> fmap ($a) y | |
Right b -> fmap (const b) y |
#include <iostream> | |
#include <string> | |
struct BordelLand { | |
BordelLand(bool x): tag(Graffiti::A), a(x) {} | |
BordelLand(char x): tag(Graffiti::B), b(x) {} | |
BordelLand(float x): tag(Graffiti::C), c(x) {} | |
template <typename F> void pattern_a(F f) { | |
if (tag == Graffiti::A) { |
use serde::de::{Deserialize, Deserializer, Error, Visitor}; | |
use std::fmt; | |
use serde_json::de::from_str; | |
#[derive(Clone, Debug, Eq, PartialEq)] | |
enum YourFancyEnum { | |
Foo, | |
Bar, | |
Zoo, |
I hereby claim:
To claim this, I am signing this object: