Skip to content

Instantly share code, notes, and snippets.

View lgastako's full-sized avatar

John lgastako

  • Francon & Heyer
  • Milky Way Galaxy, Third Rock from the Sun
View GitHub Profile
@chshersh
chshersh / ArrayFun.hs
Last active August 15, 2019 05:27
Emulating array syntax with lens
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | This module contains some approach for emulating array syntax from
-- imperative languages. The approach emulates only syntax, not efficiency.
-- Though if you like working with persistent arrays it may be good for you.
-- Also it's a fun exercise on lenses.
@andrevdm
andrevdm / Scotty_websockets.hs
Last active March 6, 2024 01:51
Using websockets with scotty haskell
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Protolude
import qualified Web.Scotty as Sc
import qualified Data.Text as Txt
import qualified Network.Wai.Middleware.Gzip as Sc

Here's a question on using the Unison language.

I wanted to play around with defining APIs for data sources/sinks/feeds etc, but I hit a wall. I don't know how I should define an API in unison without tying down the underlying datatype used to implement it.

As a example, consider the following bit of Haskell.

-- let's ignore for the purposes of this discussion whether this is a wise definition of a stream...
class StreamT s where
 get :: s a -> (a, s a)
@chessai
chessai / aesont.hs
Created February 26, 2019 18:36
derive json automatically for the way i usually write my record product types
data Settings = Settings
{ settingsFoo :: Int
, settingsBar :: String
, settingsBaz :: [Int]
}
deriving (stock) Generic
instance FromJSON Settings where
parseJSON = parseJSONFielded
@ChrisPenner
ChrisPenner / Optics Cheatsheet.md
Last active April 21, 2025 12:45
Optics Cheatsheet
@gelisam
gelisam / StringPattern.hs
Created January 30, 2020 14:39
A Haskell reimplementation of Scala's "direct pattern-matching on strings"
-- in response to https://twitter.com/chrislpenner/status/1221784005156036608
--
-- The goal is to mimic this Scala code, but in Haskell:
--
-- > "spotify:user:123:playlist:456" match {
-- > case s"spotify:user:$userId:playlist:$playlistId"
-- > => ($userId, $playlistId) // ("123", "456")
-- > }
{-# LANGUAGE DeriveFunctor, LambdaCase, PatternSynonyms, QuasiQuotes, RankNTypes, TemplateHaskell, TypeOperators, ViewPatterns #-}
{-# OPTIONS -Wno-name-shadowing #-}
@donovancrichton
donovancrichton / fibequiv.idr
Last active February 26, 2020 09:19
Proving extensionally equivalent fibonacci functions using Idris
%default total
||| A stream (an infinite list) of natural numbers representing the
||| fibbonacci sequence.
fibs : Stream Nat
fibs = f 0 1
where
f : Nat -> Nat -> Stream Nat
f a b = a :: f b (a + b)

Monads and delimited control are very closely related, so it isn’t too hard to understand them in terms of one another. From a monadic point of view, the big idea is that if you have the computation m >>= f, then f is m’s continuation. It’s the function that is called with m’s result to continue execution after m returns.

If you have a long chain of binds, the continuation is just the composition of all of them. So, for example, if you have

m >>= f >>= g >>= h

then the continuation of m is f >=> g >=> h. Likewise, the continuation of m >>= f is g >=> h.

{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Fizz where
import Protolude
fizzBuzz :: IO ()
fizzBuzz = run fizzBuzzRules
@Kazark
Kazark / CurryHoward.lhs
Last active June 6, 2024 23:47
Curry-Howard Tutorial in Literate Haskell
This is a tutorial on the Curry-Howard correspondence, or the correspondence
between logic and type theory, written by Keith Pinson, who is still a learner
on this subject. If you find an error, please let me know.
This is a Bird-style literate Haskell file. Everything is a comment by default.
Lines of actual code start with `>`. I recommend that you view it in an editor
that understands such things (e.g. Emacs with `haskell-mode`). References will
also be made to Scala, for programmers less familiar with Haskell.
We will need to turn on some language extensions. This is not an essay on good