Follow the Unison Programming Language Guide
Use the Unison programming language for all code unless otherwise specified.
Use the following procedure to assist me with writing code.
| -- This gist shows how we can use abilities to provide nicer syntax for any monad. | |
| -- We can view abilities as "just" providing nicer syntax for working with the | |
| -- free monad. | |
| ability Monadic f where | |
| eval : f a -> a | |
| -- Here's a monad, encoded as a first-class value with | |
| -- two polymorphic functions, `pure` and `bind` | |
| type Monad f = Monad (forall a . a -> f a) (forall a b . f a -> (a -> f b) -> f b) |
| -- Structure: a buffer of Arity, then a list of complete trees of exponentially increasing size | |
| type Skew a = Skew [a] [(Nat, [Skew.Tree a])] | |
| type Skew.Tree a = Tree [a] [Skew.Tree a] | |
| Skew.Arity = 4 | |
| Skew.cons : a -> Skew a -> Skew a | |
| Skew.cons a = cases Skew hd spine -> | |
| hd' = a +: hd | |
| if List.size hd' < Arity then Skew hd' spine |
| module Elmz.Layout where | |
| import List | |
| import Array (Array) | |
| import Either(..) | |
| import Graphics.Element as E | |
| import Graphics.Element (Direction, Element, Position) | |
| type Pt = { x : Int, y: Int } |
| // WARNING! totally untested, I have only compiled the code! :) | |
| package json | |
| import collection.immutable.Map | |
| import scalaz.{\/, MonadPlus} | |
| import scalaz.\/._ | |
| import scalaz.std.vector._ | |
| import scalaz.std.map._ | |
| import scalaz.std.list._ |
| unique ability Batch where | |
| increment : Nat -> () | |
| -- Like `State.transact`, but pauses the computation every `batchSize` calls to | |
| -- `Batch.increment` and commits the work so far in one transaction, then resumes | |
| -- the rest of the computation. | |
| State.transact.batched : Nat -> Database -> '{Batch, Transaction, Exception} a ->{State, Exception} a | |
| State.transact.batched batchSize db b = | |
| go : Nat -> Request {Batch} a -> Either ('{Batch,Transaction,Exception} a) a | |
| go acc = cases |
This document is licensed CC0.
These are some questions to give a sense of what you know about FP. This is more of a gauge of what you know, it's not necessarily expected that a single person will breeze through all questions. For each question, give your answer if you know it, say how long it took you, and say whether it was 'trivial', 'easy', 'medium', 'hard', or 'I don't know'. Give your answers in Haskell for the questions that involve code.
Please be honest, as the interviewer may do some spot checking with similar questions. It's not going to look good if you report a question as being 'trivial' but a similar question completely stumps you.
Here's a bit more guidance on how to use these labels:
| use data Array | |
| structural type Sequence a | |
| = Empty Nat | |
| | Sequence Nat Nat (Array a) (Sequence (Array a)) (Array a) | |
| Sequence.arity : Sequence a -> Nat | |
| Sequence.arity = cases | |
| Sequence.Empty arity -> arity | |
| Sequence arity _ _ _ _ -> arity |
This is material to go along with a 2014 Boston Haskell talk.
We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.
Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?
wrangle :: Int -> IntHere's a transcript of me updating a dependency in Unison. We're going to make this more streamlined, but this is the process for now. First, I made a copy of the branch I was updating (in this case main of distributed):
.distributed> fork main topics.baseupdate
Done.
Next I pulled the new version of base into lib.base_new: