Skip to content

Instantly share code, notes, and snippets.

View dino-'s full-sized avatar

Dino Morelli dino-

View GitHub Profile
#! /usr/bin/env runhaskell
import Text.HTML.TagSoup
main :: IO ()
main = do
tags <- fmap parseTags $ readFile "foo.xml";
let names = sections (~== "<name>") $ tags
mapM_ (\t -> putStrLn $ "saw: " ++ t ) $ map fromTagText
$ map (flip (!!) 1) names
@dino-
dino- / haskell-flip-id.md
Last active July 23, 2016 12:43
The interesting type of `foldl (flip id)`

The interesting type of foldl (flip id)

System.Console.GetOpt

Going through the example code for System.Console.GetOpt got me thinking about the type of foldl (flip id)

Specifically, the second example Interpreting flags as transformations of an options record. The code is using this to combine all of the command-line args into a record of the args as a whole.

I was confused about how foldl (flip id) has the type it does

In Haskell, it's sometimes useful to turn off buffering when writing code that uses the standard input/output file handles. That can be done to the three commonly-used handles in one line like this:

  import System.IO

  mapM_ (flip hSetBuffering NoBuffering) [ stdout, stderr, stdin ]

It's kind of terse though, let's go through what's happening in it.

@dino-
dino- / state-is-simple.hs
Created December 24, 2018 19:40
State in Haskell is simple
#!/usr/bin/env stack
-- stack --resolver lts-12.24 script
-- If stack isn't installed on your system and you can't/won't get it, install
-- a reasonably-modern GHC and use this instead of the above two lines:
-- #! /usr/bin/env runhaskell
import Control.Monad.State
@dino-
dino- / string-conversions.hs
Last active April 6, 2024 16:32
A handy illustration of converting between String, Text and ByteString in Haskell
#! /usr/bin/env stack
-- stack --resolver lts-18.8 script
{-# LANGUAGE OverloadedStrings #-}
{-
This is a handy illustration of converting between five of the commonly-used
string types in Haskell (String, ByteString, lazy ByteString, Text and lazy
Text).
#! /usr/bin/env stack
-- stack --resolver lts-13.15 runghc --package mtl
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad.Except
main :: IO ()
main = do
@dino-
dino- / keybase.md
Created July 29, 2019 00:18
Keybase proof

Keybase proof

I hereby claim:

  • I am dino- on github.
  • I am dino733 (https://keybase.io/dino733) on keybase.
  • I have a public key ASCV2424hXHoyxWn_lBsR3WEbtttYO4BTEUHwjNPPupxxQo

To claim this, I am signing this object:

@dino-
dino- / Playground.hs
Last active March 23, 2021 18:38
Plutus Playground Smart Contract
import Control.Monad ( void )
import Data.Aeson ( FromJSON, ToJSON )
import qualified Data.Text as T
import GHC.Generics ( Generic )
import Language.Plutus.Contract
import Language.PlutusTx as PlutusTx
import Language.PlutusTx.Prelude
import Ledger
import Ledger.Ada as Ada
import Ledger.Constraints as Constraints
@dino-
dino- / haskell-symbols.md
Last active March 20, 2024 05:38
Haskell symbols

Haskell symbols

When starting out with Haskell, I found it difficult to read a lot of the symbols. I made this document explaining the names of some symbols and how I read them.

:: "has type"

x :: Int

@dino-
dino- / promises.js
Created October 7, 2021 14:21
A JavaScript promises cheat-sheet
// A JavaScript promises cheat-sheet
// an immediately resolved promise
const p1 = Promise.resolve('foo');
// can get it after the fact, unlike events
p1.then((res) => console.log('p1 got:', res));
// => p1 got: foo