Advertisement
Guest User

haskell type family

a guest
Apr 12th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ListLike l where
  2.   type Elem l
  3.   indexl :: l -> Int -> Elem l
  4.  
  5. instance ListLike (V.Vector a) where
  6.   type Elem (V.Vector a) = a
  7.   indexl = (V.!)
  8.  
  9. instance ListLike [a] where
  10.   type Elem [a] = a
  11.   indexl = (!!)
  12.  
  13. cutrod ::
  14.   forall l.
  15.   ListLike l =>
  16.   l ->
  17.   Int ->
  18.   Int
  19. cutrod v n = go 1 0
  20.   where
  21.     go l result | l == n + 1 = result
  22.     go l result | otherwise = go (l + 1) result'
  23.      where
  24.        result' = maximum [result + (indexl v 0), (indexl v (l - 1))]
  25.  
  26.  
  27. src/MyLib.hs:50:38-47: error:
  28.     • Couldn't match expected type ‘Int’ with actual type ‘Elem l’
  29.    • In the second argument of ‘(+)’, namely ‘(indexl v 0)’
  30.      In the expression: result + (indexl v 0)
  31.      In the first argument of ‘maximum’, namely
  32.        ‘[result + (indexl v 0), (indexl v (l - 1))]’
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement