Ocaml

Other Ocaml solutions.
open Base

type nucleotide = A | C | G | T

let hamming_distance a b =
  match List.zip a b with
  | [] -> 0
  | [ ([ (x :: xs) ] :: rest) ] -> 1 + hamming_distance rest

Elm

Other Elm solutions.
module Hamming exposing (distance)


distance : String -> String -> Result String Int
distance left right =
    if String.length left == String.length right then
        Ok <| calculateDistance left right

    else
        Err "left and right strands must be of equal length"


calculateDistance : String -> String -> Int
calculateDistance left right =
    List.map2 Tuple.pair (String.toList left) (String.toList right)
        |> List.filter (\( a, b ) -> a /= b)
        |> List.length

Roc

Other Roc solutions.
module [distance]

distance : Str, Str -> Result U64 _
distance = \strand1, strand2 ->
    list1 = Str.toUtf8 strand1
    list2 = Str.toUtf8 strand2

    if List.len list1 != List.len list2 then
        Err InvalidInput
        else

    List.map2 list1 list2 Pair
    |> List.countIf \Pair s1 s2 -> s1 != s2
    |> Ok