---
# System prepended metadata

title: CommonEdge interview with Koki

---

# CommonEdge interview with Koki

### What's your experience with geometry? Especially differential geometry and things like parametric curves.

### Could you give a high-level overview of how you would translate a point cloud into a Bezier surface mesh?

### Fix the bugs in this function that converts a list of vectors into a list of points.

```haskell
data Vector = V2
    { dx :: Double
    , dy :: Double
    }
    
data Point = P2
    { x :: Double
    , y :: Double
    }
    
addPtVec :: Point -> Vector -> Point
addPtVec pt vec = P2 (X pt + Dx vec) (Y pt + Dy vec)
    
makeAbsolute = foldl addToLast (pure $ P2 0 0)
    where
        addToLast vec (pt :| pts) = addPtVec pt vec :| pt :: pts
```

### Given an list of values, return the greatest (without using sort or maximum).

```haskell
greatest :: Ord a => [a] -> a
greatest xs = 
```

### Given a list of values, return the second greatest (without using sort).

```haskell
secondGreatest :: Ord a => [a] -> a
secondGreatest xs =
```

### Elaborate on the benifits and drawbacks on the following methods of error handling.

#### Error

```haskell=
head :: [a] -> a
head [] = error "head of empty list"
head (x:_) = x
```

#### Maybe

```haskell
data Maybe a = Nothing | Just a

head :: [a] -> Maybe a
head [] = Nothing
head (x:_) = Just x
```

#### Either

```haskell
data Either a b = Left a | Right b

data HeadOfEmpty = HeadOfEmpty deriving (Show)

head :: [a] -> Either HeadOfEmpty a
head [] = Left HeadOfEmpty
head (x:_) = Right x
```

#### MonadThrow

`MonadThrow` is a type class from the `exceptions` package that generalizes `throwIO` to non-IO monads.

```haskell=
class MonadThrow m where
  throwM :: Exception e => e -> m a
  
instance Exception HeadOfEmpty

head :: MonadThrow m => [a] -> m a
head [] = throwM HeadOfEmpty
head (x:_) = pure x
```

