Skip to content

Instantly share code, notes, and snippets.

@dimsuz
Created April 18, 2020 18:10
Show Gist options
  • Save dimsuz/4d5dad68296df381821584935165b81f to your computer and use it in GitHub Desktop.
Save dimsuz/4d5dad68296df381821584935165b81f to your computer and use it in GitHub Desktop.
randomInUnitSphere :: State StdGen (V3 Double)
randomInUnitSphere = iterateWhile (\v -> norm v ^ 2 >= 1) random'
random' :: Random a => State StdGen a
random' = state random
-- Error
-- /home/dima/projects/raytracing/src/Main.hs:100:59-65: error:
-- • No instance for (Random (V3 Double))
-- arising from a use of ‘random'’
-- • In the second argument of ‘iterateWhile’, namely ‘random'’
-- In the expression: iterateWhile (\ v -> norm v ^ 2 >= 1) random'
-- In an equation for ‘randomInUnitSphere’:
-- randomInUnitSphere = iterateWhile (\ v -> norm v ^ 2 >= 1) random'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment