サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
Wikipedia
www.parsonsmatt.org
Exceptions kind of suck in Haskell. You don’t get a stack trace. They don’t show up in the types of functions. They incorporate a subtyping mechanism that feels more like Java casting than typical Haskell programming. A partial solution to the problem is HasCallStack - that gives us a CallStack which gets attached to error calls. However, it only gets attached to error - so you can either have Str
With the new OverloadedRecordDot language extension, we can use the . character to access stuff on records. {-# language OverloadedRecordDot #-} data User = User { name :: String } main :: IO () main = do let user = User { name = "Matt" } putStrLn user.name This is syntax sugar for the following code: import GHC.Records data User = User { name :: String } instance HasField "name" User String where
A plea to Haskellers everywhere. Haskell has a hiring problem. There aren’t many Haskell jobs, and there aren’t many Haskell employees. Haskell employees tend to be senior engineers, and the vast majority of job ads want senior-level Haskell candidates. The vast majority of Haskell users do not have any professional production experience, and yet almost every job wants production Haskell experienc
You’re a Haskell programmer, which means you complain about compilation times. We typically spend a lot of time waiting for GHC to compile code. To some extent, this is unavoidable - GHC does a tremendous amount of work for us, and we only ever ask it to do more. At some point, we shouldn’t be terribly surprised that “doing more work” ends up meaning “taking more time.” However, there are some thi
To help write robust, reliable, and easy-to-test software, I always recommend purifying your code of effects. There are a bunch of tricks and techniques to accomplish this sort of thing, and I’m going to share one of my favorites. I have implemented a pure data pipeline that imports records from one database and puts them in another database with a slightly different schema. Rather than implement
… and your bugs smaller In my post “Type Safety Back and Forth”, I discussed two different techniques for bringing type safety to programs that may fail. On the one hand, you can push the responsibility forward. This technique uses types like Either and Maybe to report a problem with the inputs to the function. Here are two example type signatures: safeDivide :: Int -> Int -> Maybe Int lookup :: O
Supercharge your Haskell development experience with ghcid! ghcid is – at the current moment – the most important tool for Haskell development environments. It is fast, reliable, works on all kinds of projects, and is remarkably versatile. You can use it with any editor workflow, primarily by not integrating your editor! (though there are integrations available if you’re brave) For these reasons,
There’s a kind fellow named lunaris on the FPChat slack channel that shares exceptionally good advice. Unfortunately, due to the ephemeral nature of Slack, a lot of this advice is lost to history. I’ve been pestering him to write up his advice in a blog so that it could be preserved. He hasn’t posted it yet, so I’m going to start posting his rants for him ;) lunaris works with a company called Hab
The question of “How do I design my application in Haskell?” comes up a lot. There’s a bunch of perspectives and choices, so it makes sense that it’s difficult to choose just one. Do I use plain monad transformers, mtl, just pass the parameters manually and use IO for everything, the ReaderT design pattern, free monads, freer monads, some other kind of algebraic effect system?! The answer is: why
Someone posted a Treap implementation to reddit that was slow. Let’s analyze it and determine what’s up. The repo is available here Base Run I set the code up in a Cabal project, created a makefile, and ran an initial profiling run. The code and profiling output are in the base branch on GitHub. Before we look at any of the executing code or profilign output, let’s check out the definition of the
This post is intended to be a short guide on using MonadBaseControl effectively in Haskell code without understanding it. Tiny synopsis The big idea behind MonadIO m is that you can perform a transformation IO a -> m a. The big idea behind MonadBaseControl is that you can perform a transformation m a -> IO a. Most monads have additional context than just IO, so to go from your custom monad to IO r
Types are a powerful construct for improving program safety. Haskell has a few notable ways of handling potential failure, the most famous being the venerable Maybe type: data Maybe a = Nothing | Just a We can use Maybe as the result of a function to indicate: Hey, friend! This function might fail. You’ll need to handle the Nothing case. This allows us to write functions like a safe division funct
Dependently typed programming is becoming all the rage these days. Advocates are talking about all the neat stuff you can do by putting more and more information into the type system. It’s true! Type level programming gives you interesting new tools for designing software. You can guarantee safety properties, and in some cases, even gain performance optimizations through the use of these types. I’
Haskell type classes are a tricky concept for many Haskell beginners to learn. Most languages cannot express them at all, and they don’t have a concept that comes close. For many object oriented languages, the Interface is the closest language construct available. Ruby modules fill a similar niche. However, while these concepts both address name overloading and a kind of polymorphism, they miss so
Haskell’s abstraction facilities are awesome. Functor, Applicative, and Monad are all great, and Maybe is a pretty fantastic example of each. Lifting functions over optional values, combining optional values, and sequencing the possibility of Nothingness are pretty powerful tools for cleaning up code. The first time I refactored some Maybe infested code like: someFunc :: Int -> Maybe String someFu
This post is intended for beginners of functional programming interested in an exploration of laziness, Haskell, and recursion Haskell’s laziness enables some pretty cool tricks. The fix function is one of the neater ones, though it can be hard to understand how to use it from just the implementation and type signature. If you grab a calculator and put any number into it, you can start hitting the
It doesn’t have to be so thought out. A lot of people think that Haskell is great for expressing a problem that you understand really well, but it’s not so great for sketching out a problem and prototyping. In Ruby, you can start writing code that kinda works, and refine it to be more and more correct. In Haskell, you really have to get the code to type check before you do anything else, and if yo
November 15, 2015 A Beginner Tutorial This tutorial is aimed at people who are beginner-intermediate Haskellers looking to learn the basics of Template Haskell. I learned about the power and utility of metaprogramming in Ruby. Ruby metaprogramming is done by constructing source code with string concatenation and having the interpreter run it. There are also some methods that can be used to define
September 24, 2015 Recursive definitions are a lot of fun. The typical example of a recursive definition is the natural numbers: A natural number is either 0 or the successor of a natural number. Expressed in Haskell, this is: Zero is Zero, as you'd expect. One is Succ Zero, two is Succ (Succ Zero), etc. The natural numbers can be recursively defined like this. Extension One: Lists are extremely s
May 2, 2015 A beginner's voyage I've been working on a small application with the Haskell web framework scotty, and decided to use the package Persistent to provide database access. I had some trouble getting them to work together, and I couldn't find many complete examples that used PostgreSQL. I thought I'd put at least one example online of how I've gotten it to work thus far. Actually, I lied.
このページを最初にブックマークしてみませんか?
『parsonsmatt.org』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く