Skip to content

Instantly share code, notes, and snippets.

@tstarck
Created February 2, 2022 13:43
Show Gist options
  • Save tstarck/d391a92d92706ae781a4c2aeaff69ed7 to your computer and use it in GitHub Desktop.
Save tstarck/d391a92d92706ae781a4c2aeaff69ed7 to your computer and use it in GitHub Desktop.
GHCI usage example
module Foo where
import Data.List
comparing :: (Ord a) => (b -> a) -> b -> b -> Ordering
comparing f x y = compare (f x) (f y)
sortByLength :: [[a]] -> [[a]]
sortByLength = sortBy (comparing length)
-- This file can be loaded with GHCI:
-- $ stack ghci Foo.hs
--
-- And then the function should be available:
-- *Foo> sortByLength [[1,2,3],[4,5],[4,5,6,7]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment