# Creating a macOS app with Haskell and Swift

DevFeed: [Creating a macOS app with Haskell and Swift](<https://devfeed.tech/articles/creating-a-macos-app-with-haskell-and-swift-27913.md>)

Original publisher: [Read original article](<http://alt-romes.github.io/posts/2023-11-10-creating-a-macos-app-with-haskell-and-swift.html>)

Published: 2023-11-10T00:00:00Z

Content type: tutorial

Language: en

Sources: [Romes' Musings](<https://devfeed.tech/sources/romes-musings.md>)

Topics: [Haskell](<https://devfeed.tech/topics/haskell.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [SwiftUI](<https://devfeed.tech/topics/swiftui.md>), [interoperability](<https://devfeed.tech/topics/interoperability.md>), [Development](<https://devfeed.tech/topics/development.md>), [macOS](<https://devfeed.tech/topics/macos.md>), [Library](<https://devfeed.tech/topics/library.md>), [iOS](<https://devfeed.tech/topics/ios.md>), [iOS development](<https://devfeed.tech/topics/ios-development.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>)

Tags: [development](<https://devfeed.tech/tags/development.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [ios-development](<https://devfeed.tech/tags/ios-development.md>), [library](<https://devfeed.tech/tags/library.md>), [macos](<https://devfeed.tech/tags/macos.md>), [swift](<https://devfeed.tech/tags/swift.md>), [swiftui](<https://devfeed.tech/tags/swiftui.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This tutorial series explains how to build a native Apple-platform application with a SwiftUI interface and Haskell-based data and logic. The first part covers setting up a Haskell foreign library, exposing a function through the C FFI, compiling and linking it with a Swift executable, and calling it from a SwiftUI app.

## Source excerpt

Contents 1 Hello, Swift, it's Haskell! 1.1 Setting up the SwiftUI app 1.2 Setting up a Haskell foreign library 1.3 Linking the Haskell library with the executable 1.4 The RTS must be initialized 2 Remarks 2.1 Further Reading This is the first part of an in-depth guide into developing a native applications for Apple platforms (macOS, iOS, etc.) using Haskell with Swift and SwiftUI. This is the first in a series of blog posts - covering the set-up required to call Haskell functions from Swift in an XCode project using SwiftUI. In future installements of the series, I intend to at least discuss calling functions with idiomatic Haskell types with Swift ones (both with and without marshaling), SwiftUI observation, and iOS development which requires GHC to produce code for the iOS compilation target. At the time of writing I'm using XCode 15, Cabal 3.10, and GHC 9.8. There will be some features I use that are only available in these recent versions, however, the general idea of interoperability between Haskell and Swift stands on its own regardless - the now 7 year old swift-haskell-tutorial is still similarly relevant and greatly informed my approach, despite the end result being considerably different. The end goal is to create a multi-(apple)-platform application whose UI is programmed in Swift using SwiftUI while the data and logic of the application is implemented in Haskell which is called from Swift. The series of blog posts is further accompanied by a github repository where each commit matches a step of this tutorial. If in doubt regarding any step, simply checking the matching commit for absolute confidence you are understanding the practical step correctly. Visit this link to the haskell-x-swift-project-steps repository! Furthermore, I'm writing a build tool that will facilitate setting up and building a project like this without having to go through all the manual steps: haskell-swift. This write-up has been cross-posted to Well-Typed's Blog. 1 Hello, Swift, i