Skip to content

Instantly share code, notes, and snippets.

View iokasimov's full-sized avatar
🗿

Murat Kasimov iokasimov

🗿
View GitHub Profile
@VictorTaelin
VictorTaelin / semi_improved_fft.hs
Created May 3, 2023 01:39
semi_improved_fft.hs
data Complex = C Double Double deriving Show
data Nat = E | O Nat | I Nat deriving Show
data Tree a = L a | B (Tree a) (Tree a) deriving Show
cScale :: Double -> Complex -> Complex
cScale s (C ar ai) = C (ar * s) (ai * s)
cAdd :: Complex -> Complex -> Complex
cAdd (C ar ai) (C br bi) = C (ar + br) (ai + bi)
@VictorTaelin
VictorTaelin / implementing_fft.md
Last active June 19, 2024 15:48
Implementing complex numbers and FFT with just datatypes (no floats)

Implementing complex numbers and FFT with just datatypes (no floats)

In this article, I'll explain why implementing numbers with just algebraic datatypes is desirable. I'll then talk about common implementations of FFT (Fast Fourier Transform) and why they hide inherent inefficiencies. I'll then show how to implement integers and complex numbers with just algebraic datatypes, in a way that is extremely simple and elegant. I'll conclude by deriving a pure functional implementation of complex FFT with just datatypes, no floats.

@Gabriella439
Gabriella439 / default.nix
Last active December 15, 2021 04:41
How to build ghcid using nixpkgs
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/c473cc8714710179df205b153f4e9fa007107ff9.tar.gz";
sha256 = "0q7rnlp1djxc9ikj89c0ifzihl4wfvri3q1bvi75d2wrz844b4lq";
};
compiler = "ghc921";
overlay = pkgsNew: pkgsOld: {
ghcid = pkgsNew.haskell.packages."${compiler}".ghcid;
@alpmestan
alpmestan / coyo.hs
Last active June 17, 2024 15:20
Coyoneda lemma & fmap fusion
{-# LANGUAGE GADTs #-}
import Data.Monoid
import System.Environment
data Coyoneda f a where
Coyoneda :: (b -> a) -> f b -> Coyoneda f a
instance Functor (Coyoneda f) where
fmap f (Coyoneda b2a fb) = Coyoneda (f . b2a) fb
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
import Data.Aeson (ToJSON)
import Data.ByteString (ByteString)
import Data.Map (Map, fromList)
import Data.Monoid ((<>))
@ChrisPenner
ChrisPenner / divisible-renderers.hs
Last active July 27, 2017 09:13
Splitting app state rendering into parts using Contravariant Divisible
-- Attempt splitting an 'App Renderer' into smaller renderers using the Contravariant Divisible class;
-- Didn't really work out great, seems better to just use simple contramaps to map each renderer into
-- a `Renderer AppState` and then use a monoid to fold them.
{-# language InstanceSigs #-}
module Main where
import Data.Foldable
import Data.Functor.Contravariant
import Data.Functor.Contravariant.Divisible
@chpatrick
chpatrick / solga.hs
Last active April 11, 2017 13:28
Solga - servant but better
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}

Run from ghci. Must have attoparsec available via cabal repl.

:set -XOverloadedStrings

import Prelude
import Control.Applicative
import Data.Attoparsec.Text

data IPAddress = IPAddress Int Int Int Int deriving (Eq, Show)
@michaelt
michaelt / weather.hs
Created May 17, 2015 16:46
weather.hs
{-# LANGUAGE OverloadedStrings #-}
module Main where
import System.Environment
import Data.Monoid
import Control.Monad
import Data.Aeson
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Network.HTTP.Client
{-# LANGUAGE OverloadedStrings #-}
module CommandParser where
import Data.Attoparsec.Char8
import Control.Applicative
import qualified Data.Text.Lazy as L
import Data.Text.Encoding
data Command = Retrieve | Delete | New deriving Show