Skip to content

Instantly share code, notes, and snippets.

@phadej
phadej / overlap.hs
Created July 1, 2016 09:56
OverlappingInstance workarounds
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators, UndecidableInstances #-}
#if __GLASGOW_HASKELL__ < 708
#error "requires GHC 7.10 or newer"
#endif
module Main (main) where
@Sgeo
Sgeo / gadts.rs
Last active July 14, 2023 12:14 — forked from mstewartgallus/gadts.rs
Gadts in Rust
/// This type is only every inhabited when S is nominally equivalent to T
#[derive(Debug)]
pub struct Is<S, T>(::std::marker::PhantomData<(*const S, *const T)>);
// Construct a proof of the fact that a type is nominally equivalent
// to itself.
pub fn is<T>() -> Is<T, T> { Is(::std::marker::PhantomData) }
// std::mem::transmute does not accept unsubstituted type parameters
// manual transmute as suggested by manual
@mstewartgallus
mstewartgallus / gadts.rs
Last active November 2, 2019 18:59
Gadts in Rust
/// This type is only every inhabited when S is nominally equivalent to T
pub type Is <S, T> = Is_ <S, T>;
priv struct Is_ <S, T>;
// Construct a proof of the fact that a type is nominally equivalent
// to itself.
pub fn Is <T> () -> Is <T, T> { Is_ }
pub impl <S, T> Is_ <S, T> {