-
Go to
~/.stack/global-project/stack.yaml
and change theresolver:
section tolts-10.3
. -
Add:
- https://hackage.haskell.org/package/ghc-mod-5.9.0.0/candidate/ghc-mod-5.9.0.0.tar.gz
- cabal-helper-0.8.0.0
defmodule Otp.Child do | |
@moduledoc """ | |
A simple child process that models a stack. | |
""" | |
use GenServer | |
def start_link(state, opts \\ []) do | |
GenServer.start_link(__MODULE__, state, opts) | |
end |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module Main where |
stack new project_name
to create a new stack project.package.yaml
instead of the cabal file. This is confusing because many older answers recommend
editing the cabal file, but recent versions of stack use HPack which autogenerates the cabal file from the package.yaml
file.
Editing the package.yaml
file is better than manually editing the cabal file because it automatically discovers your modules and adds
them to the cabal (otherwise you have to add every file to the modules section). Examples on HPack syntax are in https://github.com/sol/hpackstack build
.stack exec [project_name]-exe
. To run with arguments add --
before your arguments.I've been learning Haskell recently and the hardest thing so far is figuring out how to map stuff that I already know how to do in other languages to Haskell, like updating nested structures, composing state, and handling errors with state.
For me I feel that the best way to do this is to show examples of equivalent code in Haskell and another language. Because I am familiar with Rust and Rust has types that are similar to Haskell's types while also being an imperative language, the comparison code is in Rust.
default-extensions: | |
- BangPatterns | |
- ConstraintKinds | |
- DataKinds | |
- DefaultSignatures | |
- DeriveFoldable | |
- DeriveFunctor | |
- DeriveGeneric | |
- DeriveLift | |
- DeriveTraversable |
module Main where | |
import Conduit | |
import Control.Concurrent (forkIO) | |
import Control.Concurrent.STM | |
import Data.Conduit.Network | |
import Data.ByteString hiding (putStrLn) | |
import Data.String | |
import qualified Data.STM.RollingQueue as RQ |
module Main where | |
import Control.Monad | |
import Data.List | |
newtype Indent = Indent { unIndent :: Int } deriving (Show, Eq) | |
squareText :: String -> Maybe String | |
squareText [] = Nothing | |
squareText [_] = Nothing |
{-# LANGUAGE TypeInType #-} | |
module Main where | |
import Control.Concurrent.STM | |
import Control.Exception.Base | |
import Control.Monad.Except | |
import Control.Monad.Identity | |
import Control.Monad.Reader | |
import Control.Monad.State |