Posted on March 27, 2021

Examples of beautiful haskell code


module Main where

import System.IO

main = readFile "input.txt" >>= print.length.lines


[Lazy Pattern Matching]

{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}

class Foo a where 
    foo :: a 

instance a ~ Int => Foo (a -> Int) where 
    foo k = k

instance (a ~ Int, b ~ Int) => Foo (a -> b -> Int) where 
    foo k l = k+l

instance (a ~ String) => Foo (a -> String) where 
    foo k = k

-- | usage: 
-- | foo 1 :: Int
-- | foo 1 2 :: Int
-- | foo "bar":: String

[Transpose]

-- | Both of these produce a transpose:
t' = transpose . V.toList $ d
t' = getZipList . sequenceA . map ZipList $ V.toList v'

comments powered by Disqus