Reconstruir uma árvore binária a partir de listas de pré-encomenda e inorder

Oi, eu estou tentando reconstruir uma árvore binária, quase consegui, exceto que isso gera um erro e não sei por que

buildTree :: (Ord a, Eq a) => [a] -> [a] -> Tree a
buildTree [] [] = Empty
buildTree preOrd inOrd = Node root left right 
where root  = head preOrd
      left = buildTree leftPreOrd leftInOrd
      right = buildTree rigthPreOrd leftInOrd

      Just rootInd = elemIndex root inOrd
      leftPreOrd   = tail (take (rootInd + 1) preOrd)
      rigthPreOrd  = tail (drop rootInd preOrd)

      leftInOrd    = take rootInd inOrd
      rightInord   = drop (rootInd + 1) inOrd

Quando eu ligo usando

buildTree [10,5,2,6,14,12,15] [2,5,6,10,12,14,15]

isso me joga isso:

Exception: reconstruir.hs:26:11-45: Irrefutable pattern failed for pattern Just rootInd

questionAnswers(2)

yourAnswerToTheQuestion