Skip to content

Instantly share code, notes, and snippets.

@oldfartdeveloper
Last active March 29, 2020 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldfartdeveloper/c786cf33571c38483af44bbac1f383a3 to your computer and use it in GitHub Desktop.
Save oldfartdeveloper/c786cf33571c38483af44bbac1f383a3 to your computer and use it in GitHub Desktop.
Cartesian product Exercise that I can't seem to get to compile on Purescript

Here's the code as part of a coding exercise (the 2nd one) here:

module CartesianProductExercise where
  
import Prelude

import Data.Tuple (Tuple(..))

cartesianProduct ::  a b. Array a -> Array b -> Array (Tuple a b)
cartesianProduct left right = do
  a_ <- left
  b_ <- right
  pure[ Tuple a_ b_ ]

The error that spago returns is:

Compiling CartesianProductExercise
Error found:
in module CartesianProductExercise
at src/CartesianProductExercise.purs:9:3 - 9:13 (line 9, column 3 - line 9, column 13)

  Could not match type
         
    Array
         
  with type
            
    Tuple a0
            

while trying to match type Array (Tuple a0 b1)
  with type Tuple a0 b1
while checking that expression (bind left) (\a_ ->                 
                                              (bind right) (\b_ -> 
                                                              ...  
                                                           )       
                                           )                       
  has type Array (Tuple a0 b1)
in value declaration cartesianProduct

where b1 is a rigid type variable
        bound at (line 0, column 0 - line 0, column 0)
      a0 is a rigid type variable
        bound at (line 0, column 0 - line 0, column 0)

See https://github.com/purescript/documentation/blob/master/errors/TypesDoNotUnify.md for more information,
or to contribute content related to this error.


[error] Failed to build.

What I'm trying to do is specify a Tuple so that I can match the types of the two arrays.

Can anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment