SlideShare a Scribd company logo
Writing Better
   Haskell
TL;DR:You can start off
  bad, and get better
Case Study: Kit
$ cabal install kit
Dependency manager for Obj-C code
Kit’s Origins

• 80% of the functionality needed produced
  in one (alcohol fueled) weekend
• Very little Haskell knowledge
• No internet access, no guidance.
It’s bad code.
How bad?

• IO everywhere
• Very little usage of the standard library, or
  any other libraries
• General ugliness
It could only get better.
Clearing out IO
Kit’s IO

• Producing Xcode projects - project files,
  config files
• Reading Specs - a configuration file for a
  Kit
Writing Files


createKitConfig :: Config -> IO ()
FS Actions
• data FSAction =
• FileCreate FilePath String |
• Symlink FilePath FilePath |
• InDir FilePath FSAction

• runAction :: FSAction -> IO ()
FSAction

createKitConfig :: Config -> FSAction


setupKitDirectory :: KitSpec ->
[FSAction]
Next: Cleaning IO

• Reader monad for specifying the
  Environment
• Writer monad for pure logging
• State monad for pure repository
  manipulation
Learning the
   StdLib
   [and hackage]
Unfolding
        Dependencies
• treeDependencies :: Kit -> Tree Kit
• totalDependencies :: Kit -> [Kit]

• Order is actually important.
Unfolding
        Dependencies

• Preserve order: lowest level deps first, keep
  dep order listing from Spec file


• No duplicates
Unfolding
        Dependencies


nub . concat . reverse . drop 1 . levels
Other learns:
• Globbing:
 • Shelling out to ruby, vs
 • the glob package
• CmdArgs:
 • Pattern match on arrays of args, vs
 • CmdArgs package
General Ugliness
    Tidying up imports
Prefix headers


• Used in [Obj-]C applications to provide
  global imports.
• Application-specific base library
Before
• import System.FilePath.Posix
• import System.Directory
• import Control.Applicative
• import Control.Monad

• In every damn file.
After
module Kit.Util(
 module Kit.Util,
 module Control.Applicative,
 module Control.Monad,
 module System.Directory,
 module System.FilePath.Posix
 ) where
After


• import Kit.Util
So, is it good yet?
No.
• Plug through WriterT for Logging
• Remove IO from the Monad stack
• When IO is gone, define invariants in
  quickcheck properties
• Learn how to specify those properties
  through types

More Related Content

PDF
Pharo Status ESUG 2014
PDF
PharoDAYS 2015: Pharo Status - by Markus Denker
PDF
Reflection in Pharo5
PDF
perlcc made easy or, how to make a CGI Moose app
PDF
Pharo VM Performance
PPTX
Introducing .NET Core Open Source
PDF
Gatling @ Scala.Io 2013
Pharo Status ESUG 2014
PharoDAYS 2015: Pharo Status - by Markus Denker
Reflection in Pharo5
perlcc made easy or, how to make a CGI Moose app
Pharo VM Performance
Introducing .NET Core Open Source
Gatling @ Scala.Io 2013

What's hot (20)

PPTX
Creating SaltStack State data with Pyobjects
PDF
Queick: A Simple Job Queue System for Python
PPTX
Task queuing with redis and rq
KEY
Crash reports pycodeconf
ODP
Microservices with Apache Camel
PDF
OHHttpStubs
PDF
From 'dotnet run' to 'hello world'
PDF
Pharo Status Fosdem 2015
KEY
Event machine
KEY
Celery
PDF
Kafka Workshop
PPTX
Neutron upgrades
PPT
Ruby eventmachine pres at rubybdx
PDF
Pharo: A Reflective System
PDF
10 Things you should know about Ruby
PDF
All of the thing about Postman
PPTX
Flask
ODP
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
PDF
Raspberry and Pharo
PDF
faastRuby - Building a FaaS platform with Redis (RedisConf19)
Creating SaltStack State data with Pyobjects
Queick: A Simple Job Queue System for Python
Task queuing with redis and rq
Crash reports pycodeconf
Microservices with Apache Camel
OHHttpStubs
From 'dotnet run' to 'hello world'
Pharo Status Fosdem 2015
Event machine
Celery
Kafka Workshop
Neutron upgrades
Ruby eventmachine pres at rubybdx
Pharo: A Reflective System
10 Things you should know about Ruby
All of the thing about Postman
Flask
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
Raspberry and Pharo
faastRuby - Building a FaaS platform with Redis (RedisConf19)
Ad

Similar to Writing Better Haskell (20)

PDF
WTF is Twisted?
PDF
Packaging perl (LPW2010)
PPTX
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
PDF
Code quality par Simone Civetta
PPTX
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
PPTX
ITB2015 - Go Commando with CommandBox CLI
PDF
Mobile Fest 2018. Алексей Лизенко. Make your project great again
PDF
Command box
PDF
PDF
Deliver Python Apps with Docker
PDF
CommandBox at CFCamp 2014
PDF
Raffaele Rialdi
PDF
Steamlining your puppet development workflow
PDF
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
PDF
Docker Introduction
PPTX
Hot to build continuously processing for 24/7 real-time data streaming platform?
PDF
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
PDF
Masterin Large Scale Java Script Applications
PDF
Building static libraries for iOS with CocoaPods
PPTX
Fluo CICD OpenStack Summit
WTF is Twisted?
Packaging perl (LPW2010)
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
Code quality par Simone Civetta
Advanced Internet of Things firmware engineering with Thingsquare and Contiki...
ITB2015 - Go Commando with CommandBox CLI
Mobile Fest 2018. Алексей Лизенко. Make your project great again
Command box
Deliver Python Apps with Docker
CommandBox at CFCamp 2014
Raffaele Rialdi
Steamlining your puppet development workflow
Puppet Camp New York 2014: Streamlining Puppet Development Workflow
Docker Introduction
Hot to build continuously processing for 24/7 real-time data streaming platform?
CFCamp2025 - Keynote Day 1 led by Luis Majano.pdf
Masterin Large Scale Java Script Applications
Building static libraries for iOS with CocoaPods
Fluo CICD OpenStack Summit
Ad

More from nkpart (6)

PPT
Introduction to Laws
KEY
Tools for writing Haskell programs
KEY
Tools for writing Haskell programs
KEY
Deriving Scalaz
KEY
Scala implicits
KEY
Taming Errors with FunctionalKit
Introduction to Laws
Tools for writing Haskell programs
Tools for writing Haskell programs
Deriving Scalaz
Scala implicits
Taming Errors with FunctionalKit

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Empathic Computing: Creating Shared Understanding
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Empathic Computing: Creating Shared Understanding
cuic standard and advanced reporting.pdf
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation

Writing Better Haskell

Editor's Notes

  • #2: \n
  • #3: And getting better is easy\n
  • #4: What Kit is\nCombines multiple dependency into one static library\nMuch easy to manage in Xcode\nEasier to manage individual deps through a KitSpec than using VC sub-modules\n\n
  • #5: Explain what kit is\nUsed in mogeneration’s day-to-day app development. Crucial to version management of our apps and dependencies.\n
  • #6: Not the best environment for cultivating good code.\n
  • #7: \n
  • #8: what does bad mean, in a haskell sense\n
  • #9: This is a story of some the ways in which I’m making that happen.\nClearing out IO\nUsing other peoples code\nGeneral ugliness\n
  • #10: First step in clearing it out is identifying what sort of IO you’re doing\nWhy is IO on a function? \nWhy is this bad? Side effecting functions are difficult to decompose\n
  • #11: Why kit does: templates\n
  • #12: Implementation writes a file to a particular sub-dir, needed to maybe create the sub-dir, and write the file.\nThis could be (and was) split up into a function that produces the content, and a function that writes the content. But at some point you still need IO deep in your application.\n\n
  • #13: 3 common file system ‘writes’\nLets me test content created, and where\nCleans up a lot of ‘create parent dirs, write file’ procedures\n
  • #14: Every file writing operation now produces an FSAction, top level functions can be IO-less, and just have many actions to run, and each action can be tested (quickchecked)\n
  • #15: next steps on clearing out IO, some of this as per tony, all are good for additional talks\n
  • #16: Pretty typical milestone when you’re learning any language, is getting to grips with the std lib. Kit was written in a vaccuum... so lots of opportunities to improve on what it did initially\n
  • #17: Dependencies form a tree\nCollapsing that tree in the wrong way caused bugs\n\n\n
  • #18: Children are needed in the list before the parent, so lowest levels deps should come first\nNo duplicates\nbig TODO: version resolution\n
  • #19: nub . reverse . tail . flatten\n
  • #20: \n
  • #21: \n
  • #22: \n
  • #23: I love applicatives, I love monads, and Kit does a *lot* of shell/FS access.\n\n\n
  • #24: \n
  • #25: Somewhat similar to package objects in scala (or a typical ruby project set up)\nUtil is probably a bad name\n\n
  • #26: \n
  • #27: Lots of things still to go, however the moral of the story (if there is one), is that it has been fairly easy to re-work parts of Kit to be better. Much easier than in other environments. Benefit of a very good type system...\n\n