#Learn haskell functional programming code#
atom – A DSL that performs compile-time task scheduling and generates code with deterministic execution time and constant memory.One of my coworkers made an awesome tool called plunge that lets you compare preprocessed code c with the original and shows what each line in the original was processed into in the preprocessed version. I’m Not the Only One Making Tools for C in Haskell There are not many other languages that would let me do this as succinctly and quickly as Haskell does. I’ve I use Haskell to do far more complicated things, like extracting the names and types of functions and global declarations or performing a transformation that inserts bounds checks or logging functions in expressions that match certain criteria. This is just a blog-post-sized toy example. Not including the type signatures, that’s just 4 lines of Haskell! The type signatures are usually inferred anyway, but it’s customary to include them as doc strings. IsFooIdent (Ident name _ _) = name = "foo" IsIfOfInterest (CIf cond _ _ _) = not (null (listify isFooIdent cond)) ParseAndFindFoos path = liftM (fmap findFooLocations) (parseCFilePre path)įindFooLocations input = fmap posOf (listify isIfOfInterest input) ParseAndFindFoos :: FilePath -> IO (Either ParseError ) IsFooIdent (Ident name _ _ ) = name = "foo" IsIfOfInterest (CIf cond _ _ _ ) = not ( null (listify isFooIdent cond ) ) ParseAndFindFoos path = liftM ( fmap findFooLocations ) (parseCFilePre path )įindFooLocations input = fmap posOf (listify isIfOfInterest input ) ParseAndFindFoos :: FilePath -> IO ( Either ParseError )