Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE RankNTypes, TypeInType, TypeApplications, OverloadedLabels,
ScopedTypeVariables, TypeOperators, GADTs, FlexibleInstances, FlexibleContexts,
TypeFamilies, UndecidableInstances #-}
import Data.Kind (Type)
import Data.Proxy (Proxy(..))
import GHC.Generics
import GHC.TypeLits (Symbol, KnownSymbol, symbolVal)
import Control.Lens
import Data.Generics.Product.Fields (field')
-- Compile with
-- ghc -Wall -O -fforce-recomp -ddump-simpl -dsuppress-all poly.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Poly (value, ualue, xalue) where
import Data.Proxy (Proxy (..))
@JustinSDK
JustinSDK / YCombinator.hs
Last active March 9, 2017 14:33
Y Combinator in Haskell
import Unsafe.Coerce
y :: (a -> a) -> a
y = \f -> (\x -> f (unsafeCoerce x x))(\x -> f (unsafeCoerce x x))
-- Ref: [Y Combinator in Haskell](http://stackoverflow.com/questions/4273413/y-combinator-in-haskell)
-- a fibonacci example
main = putStrLn $ show $ y (\fact -> \n -> if n < 2 then 1 else n * fact (n - 1)) 5