Skip to content

Instantly share code, notes, and snippets.

Avatar
🌚

Andrew / Kana kana-sama

🌚
View GitHub Profile
View autowire.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
-- HList lib
View loop example.hs
import Control.Arrow (loop)
replaceWithMax, replaceWithMax' :: Ord a => [a] -> [a]
replaceWithMax xs =
let (result, max) = go (xs, max)
in result
where
go ([], replacer) = ([], replacer)
go ([x], replacer) = ([replacer], x)
View qwe.ts
type NodeId = string;
type Node_ = {
id: NodeId,
label: string,
collapsed: boolean,
children: Node_[]
}
type Tree = Node_[]
View gist:e08eba6a49bcbd17e5508954159e3662
As a gaming website we want to implement a tournament service with a feature called "Back a friend".
Each player holds certain amount of bonus points. Website funds its players with bonus points based on all kind of activity. Bonus points can traded to goods and represent value like real money.
One of the social products class is a social tournament. This is a competition between players in a multi-player game like poker, bingo, etc)
Entering a tournament requires a player to deposit certain amount of entry fee in bonus points. If a player has not enough point he can ask other players to back him and get a part the prize in case of a win.
In case of multiple backers, they submit equal part of the deposit and share the winning money in the same ration.
From a technical side, the following API service with 5 endpoints should be implemented
#1 Take and fund player account
GET /take?playerId=P1&points=300 takes 300 points from player P1 account
GET /fund?playerId=P2&points=300 funds (add to balance) player P2 wi
View MyIO.hs
{-# LANGUAGE BlockArguments #-}
import Control.Monad (ap, when)
import System.Exit (exitSuccess)
data MyIO a
= GetLine (String -> MyIO a)
| PutStrLn String (MyIO a)
| ExitSuccess
| Pure a
View Q.hs
{-# LANGUAGE ConstraintKinds, PatternSynonyms #-}
{-# LANGUAGE TypeApplications, TupleSections, ScopedTypeVariables #-}
{-# LANGUAGE UndecidableInstances, RankNTypes, DerivingStrategies,
FlexibleInstances, FlexibleContexts, TypeFamilies, DeriveGeneric,
GeneralizedNewtypeDeriving, DeriveTraversable, OverloadedStrings #-}
module Q
( defaultOptions,
genericDecode,
genericEncode,
View elim.hs
{-# LANGUAGE LambdaCase, BlockArguments, EmptyCase #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeSynonymInstances, TypeOperators, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
{-# LANGUAGE TypeFamilies, GADTs, MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE DataKinds, PolyKinds, AllowAmbiguousTypes, TypeApplications, ScopedTypeVariables #-}
import GHC.Generics
import Unsafe.Coerce (unsafeCoerce)
import Data.Type.Equality
View index_of_fib_with_50_digs.hs
import Data.List (findIndex)
import Data.Maybe (fromJust)
fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
solution = fromJust $ findIndex (\x -> length (show x) == 50) fibs
View coroutine.hs
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances, LambdaCase #-}
import Control.Monad.State
import Control.Monad.Writer
import Data.Foldable
instance Monad m => Functor (CoroutineT m) where
fmap f m = CoroutineT $ do
result <- runCoroutineT m
View qwe.hs
{-# LANGUAGE DataKinds, DeriveGeneric, TypeApplications, AllowAmbiguousTypes, ScopedTypeVariables,
PolyKinds, TypeSynonymInstances, FlexibleInstances, OverloadedStrings, OverloadedLists, FlexibleContexts,
TypeOperators #-}
import Data.Aeson
import Data.Proxy
import Data.Typeable
import qualified Data.ByteString.Lazy.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Text as T
You can’t perform that action at this time.